Creates a new CancellableToken instance.
The AbortSignal to monitor for cancellation
Optionalname: stringOptional name for this token, used for debugging
Optional ReadonlynameReadonlysignalThe AbortSignal to monitor for cancellation
Gets the current retry attempt number. Returns 0 for the initial attempt, 1 for the first retry, and so on. This is useful for tracking retry progress when retry options are configured.
The current retry attempt number (0-indexed)
Creates a cancellable delay using a custom scheduling function. The scheduling function receives a callback to invoke when the delay completes, and must return a cleanup function to cancel the scheduled operation.
The delay will stop when:
Function that schedules the delay and returns a cleanup function
A CancellableHandle that resolves when the delay completes, or can be cancelled independently of the parent token
Creates a cancellable animation frame. Uses requestAnimationFrame if available, otherwise falls back to setTimeout. The handle will be rejected if the token is cancelled before the frame callback.
A CancellableHandle that resolves on the next animation frame, or can be cancelled independently of the parent token
Executes a function repeatedly at a specified interval until cancelled. The function can be synchronous or asynchronous. Each execution waits for the previous one to complete before scheduling the next interval delay.
The interval will stop when:
The function to execute at each interval. Can return a Promise for async operations.
The interval in milliseconds to wait between executions (after each execution completes)
A CancellableHandle that can be used to cancel the interval independently of the parent token
Checks if the token has been cancelled.
True if the token has been cancelled, false otherwise
Registers a callback to be invoked when the token is cancelled. If the token is already cancelled, the callback is invoked immediately.
Function to call when cancellation occurs, receives the CancelError
A cleanup function to remove the callback listener
Creates a cancellable sleep/delay. The handle will be rejected if the token is cancelled during the sleep period.
The number of milliseconds to sleep
A CancellableHandle that resolves after the specified delay, or can be cancelled independently of the parent token
Wraps a promise or CancellableHandle to respect the cancellation token. If the token is cancelled, the wrapped promise will be rejected with a CancelError.
The type of the promise result
The promise or CancellableHandle to wrap
A promise that respects the cancellation token
Token provided to cancellable tasks for managing cancellation state and utilities. Provides methods to check cancellation status, wrap promises, sleep, and run intervals.