parallel-universe
Version:
The set of async flow control structures and promise utils.
48 lines (47 loc) • 1.61 kB
TypeScript
import { Awaitable } from './types';
/**
* The promise that can be aborted.
*
* @template T The value that the promise is resolved with.
*/
export declare class AbortablePromise<T> extends Promise<T> {
static get [Symbol.species](): PromiseConstructor;
private _abortController;
/**
* Creates a new abortable promise.
*
* @param executor A callback that initializes the promise.
* @template T The value that the promise is resolved with.
*/
constructor(executor: (
/**
* The resolve callback used to resolve the promise with a value or the result of another promise.
*
* @param value The fulfillment result.
*/
resolve: (value: Awaitable<T>) => void,
/**
* The reject callback used to reject the promise with a provided reason or error.
*
* @param reason The rejection reason.
*/
reject: (reason?: any) => void,
/**
* The signal that is aborted if {@link abort} method is called.
*/
signal: AbortSignal) => void);
/**
* Aborts the signal passed to the executor and instantly rejects the promise with the reason.
*
* @param reason The abort reason. If not explicitly provided, it defaults to an
* {@link https://developer.mozilla.org/en-US/docs/Web/API/DOMException#aborterror AbortError}.
*/
abort(reason?: unknown): void;
/**
* Subscribes this promise to be aborted when the signal is aborted.
*
* @param signal The signal that aborts this promise.
* @returns This promise.
*/
withSignal(signal: AbortSignal): this;
}