abort-utils
Version:
Utility functions to use and combine `AbortSignal` and `AbortController` with Promises
16 lines (15 loc) • 874 B
TypeScript
/**
* Like `Promise.race()`, but it accepts `AbortSignal` or `AbortController` instances.
* Think of this as a way to make a promise "abortable" (except that it doesn't actually abort the original promise).
*
* @param promise The promise to race against the signal
* @param signal The signal to listen to. If you pass a controller, it will automatically extract its signal.
* @param options.abortRejects If `false`, the promise will resolve instead of reject when the signal is aborted.
*/
declare function promiseRaceWithSignal<T>(promise: Promise<T>, signal: AbortSignal | AbortController | undefined, options: {
abortRejects?: false;
}): Promise<T | unknown>;
declare function promiseRaceWithSignal<T>(promise: Promise<T>, signal: AbortSignal | AbortController | undefined, options?: {
abortRejects: true;
}): Promise<T>;
export { promiseRaceWithSignal };