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