Intial spike of ambient cancellation #2908
Closed
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.
After consideration, I have decided not to proceed with this PR; there is significant complexity and confusion and potential performance impact, when a simpler version of things can already be achieved, at least on .NET 6+, with the inbuilt
.WaitAsync(...)
method family:This approach also has additional flexibility advantages. The downside is that we don't withdraw the command from the unsent queue. I think, on reflection, that I can live with that for the simplicity.
A separate PR will be issued with guidance on using this approach.
(status: in progress; first draft is via generative codegen, to be reviewed, validated and expanded)
Implement async cancellation (also encompasses per-command cancellation).
Design approach here is to use ambient async state (i.e.
AsyncLocal<T>
) via wrapper layers:Final API approach can be summarized as:
The return from
WithCancellation
here is anIDisposable
that simply restores the previous state; it is not a decorated database. I view this as a positive, as it avoids the fat-fingered error (if it was that style of API) that is too common with the transaction API:This currently only applies to async operations, but it is an interesting question as to whether this also work for synchronous operations. It ... isn't impossible.