async/cancellation_token_utils library
Cooperative cancellation tokens — roadmap #674.
A CancellationToken is a one-shot signal a long-running task polls to stop early. Cancellation is cooperative: the token never interrupts running code, so the task must still check CancellationToken.throwIfCancelled (or await CancellationToken.whenCancelled) at safe points. runCancellable only stops awaiting a future when the token cancels; it cannot abort the work the future represents.
Classes
- CancellationToken
- A one-shot cooperative cancellation signal.
Functions
-
runCancellable<
T> (CancellationToken token, Future< T> task()) → Future<T> -
Awaits
taskbut stops waiting iftokencancels first.
Exceptions / Errors
- CancellationException
- Thrown when work is abandoned because its CancellationToken was cancelled.