- Class: CancellationTokenSource
- Class: CancellationToken
- Class: CancelError
- Interface: CancellationTokenRegistration
- Class: CancellationTokenCountdown
- Interface: VSCodeCancellationTokenLike
- Interface: AbortSignalLike
Signals a CancellationToken that it should be canceled.
export declare class CancellationTokenSource {
constructor(linkedTokens?: Iterable<CancellationToken>);
readonly token: CancellationToken;
cancel(): Promise<void>;
close(): void;
}
Initializes a new instance of a CancellationTokenSource.
linkedTokens
<Iterable> An optional iterable of tokens to which to link this source.
By supplying a set of linked tokens, you can model a complex cancellation graph that allows you to signal
cancellation to various subsets of a more complex asynchronous operation. For example, you can create a
cancellation hierarchy where a root CancellationTokenSource
can be used to signal cancellation for all
asynchronous operations (such as when signing out of an application), with linked CancellationTokenSource
children used to signal cancellation for subsets such as fetching pages of asynchronous data or stopping
long-running background operations in a Web Worker. You can also create a CancellationTokenSource
that
is attached to multiple existing tokens, allowing you to aggregate multiple cancellation signals into
a single token.
Gets a CancellationToken linked to this source.
- Returns: <CancellationToken>
Cancels the source, returning a Promise that is settled when cancellation has completed. Any registered callbacks are executed in a later turn. If any callback raises an exception, the first such exception can be observed by awaiting the return value of this method.
- Returns: <Promise> A promise that resolves after all registered callbacks have been executed. If any callback raised an exception, the promise will be rejected with the first exception thrown.
Closes the source, preventing the possibility of future cancellation.
Propagates notifications that operations should be canceled.
export declare class CancellationToken {
constructor(canceled?: boolean);
static readonly none: CancellationToken;
static readonly canceled: CancellationToken;
static from(token: CancellationToken | VSCodeCancellationTokenLike | AbortSignalLike): CancellationToken;
static race(tokens: Iterable<CancellationToken>): CancellationToken;
static all(tokens: Iterable<CancellationToken>): CancellationToken;
readonly cancellationRequested: boolean;
readonly canBeCanceled: boolean;
throwIfCancellationRequested(): void;
register(callback: () => void): CancellationTokenRegistration;
}
Initializes a new instance of a CancellationToken.
canceled
<Boolean> An optional value indicating whether the token is canceled.
Gets a token which will never be canceled.
- Returns: <CancellationToken>
Gets a token that is already canceled.
- Returns: <CancellationToken>
Adapts a CancellationToken-like primitive from a different library.
token
<any
> A foreign token to adapt.- Returns: <CancellationToken>
Returns a CancellationToken that becomes canceled when any of the provided tokens are canceled.
tokens
<Iterable> An iterable of tokens.- Returns: <CancellationToken>
Returns a CancellationToken that becomes canceled when all of the provided tokens are canceled.
tokens
<Iterable> An iterable of tokens.- Returns: <CancellationToken>
Gets a value indicating whether cancellation has been requested.
- Returns: <Boolean>
Gets a value indicating whether the underlying source can be canceled.
- Returns: <Boolean>
Throws a CancelError if cancellation has been requested.
Registers a callback to execute when cancellation is requested.
callback
<Function> The callback to register.- Returns: <CancellationTokenRegistration>
An error thrown when an operation is canceled.
- Error
- CancelError
export declare class CancelError Extends Error {
constructor(message?: string);
}
Initializes a new instance of the CancelError class.
message
<String> An optional message for the error.
An object used to unregister a callback registered to a CancellationToken.
export interface CancellationTokenRegistration {
unregister(): void;
}
Unregisters the callback.
An object that provides a CancellationToken that becomes cancelled when all of its
containing tokens are canceled. This is similar to CancellationToken.all
, except that you are
able to add additional tokens.
export declare class CancellationTokenCountdown {
constructor(iterable?: Iterable<CancellationToken>);
readonly addedCount: number;
readonly remainingCount: number;
readonly token: CancellationToken;
add(token: CancellationToken): this;
}
Initializes a new instance of the CancellationTokenCountdown class.
iterable
<Iterable> An optional iterable of tokens to add to the countdown.
Gets the number of tokens added to the countdown.
- Returns: <Number>
Gets the number of tokens that have not yet been canceled.
- Returns: <Number>
Gets the CancellationToken for the countdown.
- Returns: <CancellationToken>
Adds a CancellationToken to the countdown.
- Returns: <CancellationTokenCountdown>
Describes a foreign cancellation primitive similar to the one provided by vscode
for extensions.
export interface VSCodeCancellationTokenLike {
readonly isCancellationRequested: boolean;
onCancellationRequested(listener: () => any): { dispose(): any; };
}
Describes a foreign cancellation primitive similar to the one used by the DOM.
export interface AbortSignalLike {
readonly aborted: boolean;
addEventListener(type: "abort", callback: () => any): any;
}