type Executor = (resolve: (value: T | PromiseLike) => void, reject: (reason?: unknown) => void) => void; type CancelListener = (reason?: unknown) => TResult; /** An extension of Promise that allows you to explicitly cancel a promise with an external reference to it. * Cancelling CancellablePromise causes it to reject with reason set to the parameter passed to the cancel method. * When CancellablePromise rejects, it provides a boolean to indicate whether it was cancelled, alongside the reason. * * @example * // Cancelling this promise * const promise = new CancellablePromise(() => {}).onCancel(console.log) * promise.cancel('User cancelled') * * // Setting up listeners for resolve, cancel and reject * // (notice calling catch after onCancel prevents catch from being called by cancellation) * new CancellablePromise(() => {}) * .then(() => console.log('Promise resolved')) * .onCancel(() => console.log('Promise was cancelled')) * .catch(() => console.log('Promise was rejected but NOT cancelled')) * * // Telling whether catch was cause of cancel or not * new CancellablePromise(() => {}) * .then(() => console.log('Promise resolved')) * .catch(({ reason, wasCancelled }) => console.log('Promise was rejected. Cancelled: ' + wasCancelled)) */ export declare class CancellablePromise extends Promise { private internalIsCancelled; private isSettled; private internalCancel; constructor(executor: Executor); /** Whether this CancellablePromise was cancelled. */ get isCancelled(): boolean; /** Cancels the promise. This causes the promise to reject with { wasCancelled: true, reason: reason } * where the reason is the provided argument. * @returns The cancelled promise. */ cancel(reason?: unknown): this; private internalOnCancel; /** Allows reacting to this CancellablePromise being cancelled */ onCancel(listener: CancelListener): CancellablePromise; private internalThen; then(onFulfilled?: ((value: T) => TResult1 | PromiseLike) | null, onRejected?: ((reason: { reason: unknown; wasCancelled: boolean; }) => TResult2 | PromiseLike) | null): CancellablePromise; catch(onRejected?: ((reason: { reason: unknown; wasCancelled: boolean; }) => TResult | PromiseLike) | null): CancellablePromise; finally(onFinally?: (() => void) | null): CancellablePromise; /** Generates a CancellablePromise from a Promise. If a CancellablePromise is passed, it's returned unscathed. * WARNING: unless you attach a method to reject the original Promise with the "onCancel" param. * cancelling the resulting CancellablePromise does NOT affect the original Promise. */ static fromPromise(promise: Promise | CancellablePromise): CancellablePromise; } export {};