Whether the token owner has requested for cancellation.
Gets a Promise
that resolves when the token owner has requested for cancellation.
Adds a callback function that is called when token owner has requested for cancellation.
the function to be called asynchronously when the cancellation has been requested.
an IDisposable used to unsubscribe the cancellation callback.
Throws a PromiseCancelledError
if isCancellationRequested
is true
.
Generated using TypeDoc
Represents subscribable a cancellation notification.
Cancellation notification can be propagated by passing the same instance into cancellable callee async functions.
Like the concept of "Task cooperative cancellation" introduced in .NET Framework, when the async function implementation wants to support cancellation, it should accept an extra optional parameter of type ICancellationToken.
In your function implementation, you should do at least one of the following
async function doSomeWork(ct?: ICancellationToken) { ct.throwIfCancellationRequested(); // do something await delay(1000, ct); // do something else }
CancellationTokenSource