File size: 1,596 Bytes
9ada4bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
declare type PromiseState = 'pending' | 'fulfilled' | 'rejected';
declare type Executor<Value> = ConstructorParameters<typeof Promise<Value>>[0];
declare type ResolveFunction<Value> = Parameters<Executor<Value>>[0];
declare type RejectFunction<Reason> = Parameters<Executor<Reason>>[1];
declare type DeferredPromiseExecutor<Input = never, Output = Input> = {
    (resolve?: ResolveFunction<Input>, reject?: RejectFunction<any>): void;
    resolve: ResolveFunction<Input>;
    reject: RejectFunction<any>;
    result?: Output;
    state: PromiseState;
    rejectionReason?: unknown;
};
declare function createDeferredExecutor<Input = never, Output = Input>(): DeferredPromiseExecutor<Input, Output>;

declare class DeferredPromise<Input, Output = Input> extends Promise<Input> {
    #private;
    resolve: ResolveFunction<Output>;
    reject: RejectFunction<Output>;
    constructor(executor?: Executor<Input> | null);
    get state(): PromiseState;
    get rejectionReason(): unknown;
    then<ThenResult = Input, CatchResult = never>(onFulfilled?: (value: Input) => ThenResult | PromiseLike<ThenResult>, onRejected?: (reason: any) => CatchResult | PromiseLike<CatchResult>): DeferredPromise<ThenResult | CatchResult, Output>;
    catch<CatchResult = never>(onRejected?: (reason: any) => CatchResult | PromiseLike<CatchResult>): DeferredPromise<Input | CatchResult, Output>;
    finally(onfinally?: () => void | Promise<any>): DeferredPromise<Input, Output>;
}

export { DeferredPromise, DeferredPromiseExecutor, Executor, PromiseState, RejectFunction, ResolveFunction, createDeferredExecutor };