index.js.flow 1.7 KB

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