feat!: Invoke async message scenario factories on request #536
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We still have to invoke the factory with sync-over-async at request time and this puts a burden on the user not to use this improperly, but if we want to delay invocation of the factory until after provider states have been configured then this is the first step.
This is also obviously a breaking API change and requires a major version bump.
WithAsyncContent
makes way more sense because it's the content factory that's async, not the call to the builder asWithContentAsync
would imply. This also means the return type changes to void instead of Task.See #459
We should also investigate making the internal messaging server itself async so that we don't have to do the sync-over-async shenanigans, which could maybe be achieved with
Task.Run
(or similar) instead of using a dedicated thread. We'd probably then also change the signature ofScenario.Factory
to beFunc<Task<dynamic>>
instead, and the sync versions would wrap inTask.FromResult
.We do get really weird behaviour when using
dynamic
insideFunc<>
though, so this has to be carefully investigated, and may not be possible.