Options
All
  • Public
  • Public/Protected
  • All
Menu

Represents subscribable a cancellation notification.

Cancellation notification can be propagated by passing the same instance into cancellable callee async functions.

remarks

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
}
see

CancellationTokenSource

Hierarchy

  • ICancellationToken

Index

Properties

isCancellationRequested

isCancellationRequested: boolean

Whether the token owner has requested for cancellation.

remarks

Note that if this field returns true, the subscribe callbacks are not guaranteed to have (all) executed.

see

ICancellationToken.throwIfCancellationRequested

promiseLike

promiseLike: IConfigurablePromiseLike<void>

Gets a Promise that resolves when the token owner has requested for cancellation.

Methods

subscribe

  • Adds a callback function that is called when token owner has requested for cancellation.

    remarks

    if the cancellation token has already been cancelled when calling this function, the callback is still guaranteed to be executed asynchronously.

    Parameters

    • callback: () => void

      the function to be called asynchronously when the cancellation has been requested.

        • (): void
        • Returns void

    Returns IDisposable

    an IDisposable used to unsubscribe the cancellation callback.

throwIfCancellationRequested

  • throwIfCancellationRequested(): void

Generated using TypeDoc