import ExtendedPromise from './Promise.js'; /** * The executor argument for new cancelable promises. * * @param resolve callback to resolve the promise with a success value * @param reject callback to reject the promise with an error * @param onCancelled accepts a cleanup function to invoke when the promise is cancelled */ type CancelablePromiseExecutor = (resolve: (value: T | PromiseLike) => void, reject: (reason?: any) => void, onCancelled: (cleanup: () => void) => void) => void; /** * Promise class which provides a 'cancel' method. * Read more about [Promises](./PROMISES.md). */ declare class CancelablePromise extends ExtendedPromise { /** * Cancels the execution of this promise. */ readonly cancel: (reason?: string) => ExtendedPromise; /** * Creates Promise instances with "cancel" function. * @param executor function defined as (resolve,reject,onCancelled)=> \{\} * @example * ```ts * const p = new CancelablePromise((resolve, reject, onCancelled) => { * onCancelled(() => { * doSomething(); * }); * }); * * // grab cancel function for later cancellation * const cancel = p.cancel; * * // now cancel * cancel(); * ``` */ constructor(executor: CancelablePromiseExecutor); /** * Creates CancelablePromise around the given promise. * * @param promise base promise. * @returns a cancelable promise */ static cancelable(promise: PromiseLike): CancelablePromise; } export { CancelablePromise, CancelablePromise as default }; export type { CancelablePromiseExecutor };