Comments (4)
The asynchronous methods only take a CT if the CT has a semantic meaning to the synchronization primitive (i.e., the state would change as a result of the method executing). In a MRE, the "Wait" operation does not change any state.
In other words, for a AMRE.WaitAsync(CT), the CT would only cancel the await, not have any affect on the AMRE.
You can cancel any await
using ToCancellationTokenTaskSource
, and adding CT support to WaitAsync would just wrap that anyway.
Contrast this with the Auto-Reset Event. For that type, the "Wait" operation does change the event state, so proper CT support is necessary.
That said, this has been a source of confusion for people, and I'm considering adding CT support even when the semantics are only to cancel the awaits, in a future .NET Core version.
from asyncex.
Thanks for this info, I took a look at ToCancellationTokenTaskSource but I didn't find any tests / examples of this. I'm guessing you were doing a continue with on the ToCancellationTokenTaskSource??
from asyncex.
You can use it like this:
async Task WaitAsync(Task operation, CancellationToken token)
{
using (var ctSource = token.ToCancellationTokenTaskSource())
{
await await Task.WhenAny(operation, ctSource.Task);
}
}
from asyncex.
Thanks! :)
from asyncex.
Related Issues (20)
- AsyncCollection IsEmpty HOT 3
- [Discussion] Return `ValueTask` instead of `AwaitableDisposable`? HOT 5
- [Question] .WaitAndUnwrapException() vs AsyncContext and potential deadlock HOT 2
- The collection has been marked as complete with regards to additions HOT 1
- Atomic wait semantics lead to continued processing after cancellation HOT 3
- What happened to NotifyTask? HOT 1
- CancellationTokenTaskSource's dispose
- Using LazyAsync with JSONSeralizer? HOT 1
- Producer/Consumer PriorityQueue
- doc/TaskConstants.md links to an article that doesn't exist anymore
- Cross thread Sync context stealing HOT 2
- [Question] Using discard with AsyncLock HOT 1
- [Question] Is ConfigureAwait(false) is needed? HOT 1
- AsyncContext holds exceptions until all tasks complete.
- Feature request: AsyncReaderWriterLock support for UpgradeableReadLock HOT 11
- The ApmAsyncFactory interop hangs if a path in async method returns synchronously. HOT 1
- Setting AsyncAutoResetEvent after used in Task.WhenAny HOT 3
- AsyncLazy with API call is being called twice across 4 components. HOT 2
- Strong names HOT 5
- Using `AsyncLock` magically causes tasks to complete HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from asyncex.