index.d.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /**
  2. * Represents the completion of an asynchronous operation
  3. */
  4. interface ThenPromise<T> extends Promise<T> {
  5. /**
  6. * Attaches callbacks for the resolution and/or rejection of the ThenPromise.
  7. * @param onfulfilled The callback to execute when the ThenPromise is resolved.
  8. * @param onrejected The callback to execute when the ThenPromise is rejected.
  9. * @returns A ThenPromise for the completion of which ever callback is executed.
  10. */
  11. then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): ThenPromise<TResult1 | TResult2>;
  12. /**
  13. * Attaches a callback for only the rejection of the ThenPromise.
  14. * @param onrejected The callback to execute when the ThenPromise is rejected.
  15. * @returns A ThenPromise for the completion of the callback.
  16. */
  17. catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null): ThenPromise<T | TResult>;
  18. // Extensions specific to then/promise
  19. /**
  20. * Attaches callbacks for the resolution and/or rejection of the ThenPromise, without returning a new promise.
  21. * @param onfulfilled The callback to execute when the ThenPromise is resolved.
  22. * @param onrejected The callback to execute when the ThenPromise is rejected.
  23. */
  24. done(onfulfilled?: ((value: T) => any) | undefined | null, onrejected?: ((reason: any) => any) | undefined | null): void;
  25. /**
  26. * Calls a node.js style callback. If none is provided, the promise is returned.
  27. */
  28. nodeify(callback: void | null): ThenPromise<T>;
  29. nodeify(callback: (err: Error, value: T) => void): void;
  30. }
  31. interface ThenPromiseConstructor {
  32. /**
  33. * A reference to the prototype.
  34. */
  35. readonly prototype: ThenPromise<any>;
  36. /**
  37. * Creates a new ThenPromise.
  38. * @param executor A callback used to initialize the promise. This callback is passed two arguments:
  39. * a resolve callback used resolve the promise with a value or the result of another promise,
  40. * and a reject callback used to reject the promise with a provided reason or error.
  41. */
  42. new <T>(executor: (resolve: (value?: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => any): ThenPromise<T>;
  43. /**
  44. * Creates a ThenPromise that is resolved with an array of results when all of the provided Promises
  45. * resolve, or rejected when any ThenPromise is rejected.
  46. * @param values An array of Promises.
  47. * @returns A new ThenPromise.
  48. */
  49. all<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike <T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>, T10 | PromiseLike<T10>]): ThenPromise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>;
  50. /**
  51. * Creates a ThenPromise that is resolved with an array of results when all of the provided Promises
  52. * resolve, or rejected when any ThenPromise is rejected.
  53. * @param values An array of Promises.
  54. * @returns A new ThenPromise.
  55. */
  56. all<T1, T2, T3, T4, T5, T6, T7, T8, T9>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike <T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>]): ThenPromise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>;
  57. /**
  58. * Creates a ThenPromise that is resolved with an array of results when all of the provided Promises
  59. * resolve, or rejected when any ThenPromise is rejected.
  60. * @param values An array of Promises.
  61. * @returns A new ThenPromise.
  62. */
  63. all<T1, T2, T3, T4, T5, T6, T7, T8>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike <T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>]): ThenPromise<[T1, T2, T3, T4, T5, T6, T7, T8]>;
  64. /**
  65. * Creates a ThenPromise that is resolved with an array of results when all of the provided Promises
  66. * resolve, or rejected when any ThenPromise is rejected.
  67. * @param values An array of Promises.
  68. * @returns A new ThenPromise.
  69. */
  70. all<T1, T2, T3, T4, T5, T6, T7>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike <T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>]): ThenPromise<[T1, T2, T3, T4, T5, T6, T7]>;
  71. /**
  72. * Creates a ThenPromise that is resolved with an array of results when all of the provided Promises
  73. * resolve, or rejected when any ThenPromise is rejected.
  74. * @param values An array of Promises.
  75. * @returns A new ThenPromise.
  76. */
  77. all<T1, T2, T3, T4, T5, T6>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike <T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>]): ThenPromise<[T1, T2, T3, T4, T5, T6]>;
  78. /**
  79. * Creates a ThenPromise that is resolved with an array of results when all of the provided Promises
  80. * resolve, or rejected when any ThenPromise is rejected.
  81. * @param values An array of Promises.
  82. * @returns A new ThenPromise.
  83. */
  84. all<T1, T2, T3, T4, T5>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike <T4>, T5 | PromiseLike<T5>]): ThenPromise<[T1, T2, T3, T4, T5]>;
  85. /**
  86. * Creates a ThenPromise that is resolved with an array of results when all of the provided Promises
  87. * resolve, or rejected when any ThenPromise is rejected.
  88. * @param values An array of Promises.
  89. * @returns A new ThenPromise.
  90. */
  91. all<T1, T2, T3, T4>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike <T4>]): ThenPromise<[T1, T2, T3, T4]>;
  92. /**
  93. * Creates a ThenPromise that is resolved with an array of results when all of the provided Promises
  94. * resolve, or rejected when any ThenPromise is rejected.
  95. * @param values An array of Promises.
  96. * @returns A new ThenPromise.
  97. */
  98. all<T1, T2, T3>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>]): ThenPromise<[T1, T2, T3]>;
  99. /**
  100. * Creates a ThenPromise that is resolved with an array of results when all of the provided Promises
  101. * resolve, or rejected when any ThenPromise is rejected.
  102. * @param values An array of Promises.
  103. * @returns A new ThenPromise.
  104. */
  105. all<T1, T2>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>]): ThenPromise<[T1, T2]>;
  106. /**
  107. * Creates a ThenPromise that is resolved with an array of results when all of the provided Promises
  108. * resolve, or rejected when any ThenPromise is rejected.
  109. * @param values An array of Promises.
  110. * @returns A new ThenPromise.
  111. */
  112. all<T>(values: (T | PromiseLike<T>)[]): ThenPromise<T[]>;
  113. /**
  114. * Creates a ThenPromise that is resolved or rejected when any of the provided Promises are resolved
  115. * or rejected.
  116. * @param values An array of Promises.
  117. * @returns A new ThenPromise.
  118. */
  119. race<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>, T10 | PromiseLike<T10>]): ThenPromise<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9 | T10>;
  120. /**
  121. * Creates a ThenPromise that is resolved or rejected when any of the provided Promises are resolved
  122. * or rejected.
  123. * @param values An array of Promises.
  124. * @returns A new ThenPromise.
  125. */
  126. race<T1, T2, T3, T4, T5, T6, T7, T8, T9>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>]): ThenPromise<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9>;
  127. /**
  128. * Creates a ThenPromise that is resolved or rejected when any of the provided Promises are resolved
  129. * or rejected.
  130. * @param values An array of Promises.
  131. * @returns A new ThenPromise.
  132. */
  133. race<T1, T2, T3, T4, T5, T6, T7, T8>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>]): ThenPromise<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8>;
  134. /**
  135. * Creates a ThenPromise that is resolved or rejected when any of the provided Promises are resolved
  136. * or rejected.
  137. * @param values An array of Promises.
  138. * @returns A new ThenPromise.
  139. */
  140. race<T1, T2, T3, T4, T5, T6, T7>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>]): ThenPromise<T1 | T2 | T3 | T4 | T5 | T6 | T7>;
  141. /**
  142. * Creates a ThenPromise that is resolved or rejected when any of the provided Promises are resolved
  143. * or rejected.
  144. * @param values An array of Promises.
  145. * @returns A new ThenPromise.
  146. */
  147. race<T1, T2, T3, T4, T5, T6>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>]): ThenPromise<T1 | T2 | T3 | T4 | T5 | T6>;
  148. /**
  149. * Creates a ThenPromise that is resolved or rejected when any of the provided Promises are resolved
  150. * or rejected.
  151. * @param values An array of Promises.
  152. * @returns A new ThenPromise.
  153. */
  154. race<T1, T2, T3, T4, T5>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>]): ThenPromise<T1 | T2 | T3 | T4 | T5>;
  155. /**
  156. * Creates a ThenPromise that is resolved or rejected when any of the provided Promises are resolved
  157. * or rejected.
  158. * @param values An array of Promises.
  159. * @returns A new ThenPromise.
  160. */
  161. race<T1, T2, T3, T4>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>]): ThenPromise<T1 | T2 | T3 | T4>;
  162. /**
  163. * Creates a ThenPromise that is resolved or rejected when any of the provided Promises are resolved
  164. * or rejected.
  165. * @param values An array of Promises.
  166. * @returns A new ThenPromise.
  167. */
  168. race<T1, T2, T3>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>]): ThenPromise<T1 | T2 | T3>;
  169. /**
  170. * Creates a ThenPromise that is resolved or rejected when any of the provided Promises are resolved
  171. * or rejected.
  172. * @param values An array of Promises.
  173. * @returns A new ThenPromise.
  174. */
  175. race<T1, T2>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>]): ThenPromise<T1 | T2>;
  176. /**
  177. * Creates a ThenPromise that is resolved or rejected when any of the provided Promises are resolved
  178. * or rejected.
  179. * @param values An array of Promises.
  180. * @returns A new ThenPromise.
  181. */
  182. race<T>(values: (T | PromiseLike<T>)[]): ThenPromise<T>;
  183. /**
  184. * Creates a new rejected promise for the provided reason.
  185. * @param reason The reason the promise was rejected.
  186. * @returns A new rejected ThenPromise.
  187. */
  188. reject(reason: any): ThenPromise<never>;
  189. /**
  190. * Creates a new rejected promise for the provided reason.
  191. * @param reason The reason the promise was rejected.
  192. * @returns A new rejected ThenPromise.
  193. */
  194. reject<T>(reason: any): ThenPromise<T>;
  195. /**
  196. * Creates a new resolved promise for the provided value.
  197. * @param value A promise.
  198. * @returns A promise whose internal state matches the provided promise.
  199. */
  200. resolve<T>(value: T | PromiseLike<T>): ThenPromise<T>;
  201. /**
  202. * Creates a new resolved promise .
  203. * @returns A resolved promise.
  204. */
  205. resolve(): ThenPromise<void>;
  206. // Extensions specific to then/promise
  207. denodeify: (fn: Function) => (...args: any[]) => ThenPromise<any>;
  208. nodeify: (fn: Function) => Function;
  209. }
  210. declare var ThenPromise: ThenPromiseConstructor;
  211. export = ThenPromise;