@naturalcycles/js-lib
Version:
Standard library for universal (browser + Node.js) javascript
25 lines (24 loc) • 727 B
TypeScript
/**
* Similar to Deferred object, which is also a promise itself (instead of deferred.promise).
*/
export interface DeferredPromise<T = void> extends Promise<T> {
resolve: (a?: T) => void;
reject: (err?: Error) => void;
/**
* Can be overridden.
* Otherwise will reject with "Aborted" or "Aborted: $reason" on abort().
*
* @experimental
*/
abort: (reason?: string) => void;
/**
* Rejects the promise with `new Error('Aborted: $reason')`.
*
* @experimental
*/
rejectAborted: (reason?: string) => void;
}
/**
* Returns DeferredPromise - a Promise that has .resolve() and .reject() methods.
*/
export declare function pDefer<T = void>(): DeferredPromise<T>;