The type of value the promise resolves to (default: void)
Creates a new CancellablePromise.
The type of value the promise resolves to (default: void)
The executor function, same as native Promise.
Receives resolve and reject callbacks.
OptionalonCancel: () => voidOptional cleanup callback invoked when cancel() is called.
This runs before the promise resolves, allowing cleanup of timers, intervals, etc.
Readonly[toStatic Readonly[species]Gets whether the promise has been cancelled.
True if cancelled, false otherwise
Sets whether the promise has been cancelled.
The cancelled state
Cancels the promise, invoking the cleanup callback and resolving immediately.
This method:
onCancel callback (if provided) for cleanupCalling cancel() multiple times has no effect after the first call.
Optionalvalue: TOptional value to resolve the promise with. For void promises (default), this can be omitted.
Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The resolved value cannot be modified from the callback.
Optionalonfinally: (() => void) | nullThe callback to execute when the Promise is settled (fulfilled or rejected).
A Promise for the completion of the callback.
StaticallCreates a Promise that is resolved with an array of results when all of the provided Promises resolve, or rejected when any Promise is rejected.
An array of Promises.
A new Promise.
StaticallCreates a Promise that is resolved with an array of results when all of the provided Promises resolve or reject.
An array of Promises.
A new Promise.
StaticanyThe any function returns a promise that is fulfilled by the first given promise to be fulfilled, or rejected with an AggregateError containing an array of rejection reasons if all of the given promises are rejected. It resolves all elements of the passed iterable to promises as it runs this algorithm.
An array or iterable of Promises.
A new Promise.
The any function returns a promise that is fulfilled by the first given promise to be fulfilled, or rejected with an AggregateError containing an array of rejection reasons if all of the given promises are rejected. It resolves all elements of the passed iterable to promises as it runs this algorithm.
A new Promise.
StaticraceStaticrejectCreates a new rejected promise for the provided reason.
Optionalreason: anyThe reason the promise was rejected.
A new rejected Promise.
StaticresolveCreates a new resolved promise.
A resolved promise.
StatictryTakes a callback of any kind (returns or throws, synchronously or asynchronously) and wraps its result in a Promise.
A Promise that is:
StaticwithCreates a new Promise and returns it in an object, along with its resolve and reject functions.
An object with the properties promise, resolve, and reject.
const { promise, resolve, reject } = Promise.withResolvers<T>();
A promise that can be cancelled before completion.
Extends the native Promise class to add cancellation support. When cancelled, the promise resolves (not rejects) and calls an optional cleanup callback.
This is useful for animations and effects that need to be interruptible, allowing the final state to be shown immediately instead of waiting.
CancellablePromise
Example