| 1 | // @flow
|
|---|
| 2 |
|
|---|
| 3 | declare class ThenPromise<+R> extends Promise<R> {
|
|---|
| 4 | constructor(callback: (
|
|---|
| 5 | resolve: (result: Promise<R> | R) => void,
|
|---|
| 6 | reject: (error: any) => void
|
|---|
| 7 | ) => mixed): void;
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 | then(onFulfill: null | void, onReject: null | void): ThenPromise<R>;
|
|---|
| 11 | then<U>(
|
|---|
| 12 | onFulfill: null | void,
|
|---|
| 13 | onReject: (error: any) => Promise<U> | U
|
|---|
| 14 | ): ThenPromise<R | U>;
|
|---|
| 15 | then<U>(
|
|---|
| 16 | onFulfill: (value: R) => Promise<U> | U,
|
|---|
| 17 | onReject: null | void | ((error: any) => Promise<U> | U)
|
|---|
| 18 | ): ThenPromise<U>;
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 | catch(onReject: null | void): ThenPromise<R>;
|
|---|
| 22 | catch<U>(
|
|---|
| 23 | onReject: (error: any) => Promise<U> | U
|
|---|
| 24 | ): ThenPromise<R | U>;
|
|---|
| 25 |
|
|---|
| 26 | // Extensions specific to then/promise
|
|---|
| 27 |
|
|---|
| 28 | /**
|
|---|
| 29 | * Attaches callbacks for the resolution and/or rejection of the ThenPromise, without returning a new promise.
|
|---|
| 30 | * @param onfulfilled The callback to execute when the ThenPromise is resolved.
|
|---|
| 31 | * @param onrejected The callback to execute when the ThenPromise is rejected.
|
|---|
| 32 | */
|
|---|
| 33 | done(onfulfilled?: (value: R) => any, onrejected?: (reason: any) => any): void;
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 | /**
|
|---|
| 37 | * Calls a node.js style callback. If none is provided, the promise is returned.
|
|---|
| 38 | */
|
|---|
| 39 | nodeify(callback: void | null): ThenPromise<R>;
|
|---|
| 40 | nodeify(callback: (err: Error, value: R) => void): void;
|
|---|
| 41 |
|
|---|
| 42 | static resolve<T>(object: Promise<T> | T): ThenPromise<T>;
|
|---|
| 43 | static reject<T>(error?: any): ThenPromise<T>;
|
|---|
| 44 | static all<T: Iterable<mixed>>(promises: T): ThenPromise<$TupleMap<T, typeof $await>>;
|
|---|
| 45 | static race<T, Elem: Promise<T> | T>(promises: Iterable<Elem>): ThenPromise<T>;
|
|---|
| 46 |
|
|---|
| 47 | // Extensions specific to then/promise
|
|---|
| 48 |
|
|---|
| 49 | static denodeify(fn: Function): (...args: any[]) => ThenPromise<any>;
|
|---|
| 50 | static nodeify(fn: Function): Function;
|
|---|
| 51 | }
|
|---|
| 52 | module.exports = ThenPromise;
|
|---|