rx.async.d.ts 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. declare module Rx {
  2. export interface ObservableStatic {
  3. wrap<T>(fn: Function): Observable<T>;
  4. spawn<T>(fn: Function): Observable<T>;
  5. }
  6. export interface ObservableStatic {
  7. /**
  8. * Invokes the specified function asynchronously on the specified scheduler, surfacing the result through an observable sequence.
  9. *
  10. * @example
  11. * var res = Rx.Observable.start(function () { console.log('hello'); });
  12. * var res = Rx.Observable.start(function () { console.log('hello'); }, Rx.Scheduler.timeout);
  13. * var res = Rx.Observable.start(function () { this.log('hello'); }, Rx.Scheduler.timeout, console);
  14. *
  15. * @param {Function} func Function to run asynchronously.
  16. * @param {Scheduler} [scheduler] Scheduler to run the function on. If not specified, defaults to Scheduler.timeout.
  17. * @param [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
  18. * @returns {Observable} An observable sequence exposing the function's result value, or an exception.
  19. *
  20. * Remarks
  21. * * The function is called immediately, not during the subscription of the resulting sequence.
  22. * * Multiple subscriptions to the resulting sequence can observe the function's result.
  23. */
  24. start<T>(func: () => T, scheduler?: IScheduler, context?: any): Observable<T>;
  25. }
  26. export interface ObservableStatic {
  27. /**
  28. * Converts the function into an asynchronous function. Each invocation of the resulting asynchronous function causes an invocation of the original synchronous function on the specified scheduler.
  29. * @param {Function} function Function to convert to an asynchronous function.
  30. * @param {Scheduler} [scheduler] Scheduler to run the function on. If not specified, defaults to Scheduler.timeout.
  31. * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
  32. * @returns {Function} Asynchronous function.
  33. */
  34. toAsync<TResult>(func: () => TResult, context?: any, scheduler?: IScheduler): () => Observable<TResult>;
  35. /**
  36. * Converts the function into an asynchronous function. Each invocation of the resulting asynchronous function causes an invocation of the original synchronous function on the specified scheduler.
  37. * @param {Function} function Function to convert to an asynchronous function.
  38. * @param {Scheduler} [scheduler] Scheduler to run the function on. If not specified, defaults to Scheduler.timeout.
  39. * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
  40. * @returns {Function} Asynchronous function.
  41. */
  42. toAsync<T1, TResult>(func: (arg1: T1) => TResult, context?: any, scheduler?: IScheduler): (arg1: T1) => Observable<TResult>;
  43. /**
  44. * Converts the function into an asynchronous function. Each invocation of the resulting asynchronous function causes an invocation of the original synchronous function on the specified scheduler.
  45. * @param {Function} function Function to convert to an asynchronous function.
  46. * @param {Scheduler} [scheduler] Scheduler to run the function on. If not specified, defaults to Scheduler.timeout.
  47. * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
  48. * @returns {Function} Asynchronous function.
  49. */
  50. toAsync<T1, T2, TResult>(func: (arg1: T1, arg2: T2) => TResult, context?: any, scheduler?: IScheduler): (arg1: T1, arg2: T2) => Observable<TResult>;
  51. /**
  52. * Converts the function into an asynchronous function. Each invocation of the resulting asynchronous function causes an invocation of the original synchronous function on the specified scheduler.
  53. * @param {Function} function Function to convert to an asynchronous function.
  54. * @param {Scheduler} [scheduler] Scheduler to run the function on. If not specified, defaults to Scheduler.timeout.
  55. * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
  56. * @returns {Function} Asynchronous function.
  57. */
  58. toAsync<T1, T2, T3, TResult>(func: (arg1: T1, arg2: T2, arg3: T3) => TResult, context?: any, scheduler?: IScheduler): (arg1: T1, arg2: T2, arg3: T3) => Observable<TResult>;
  59. /**
  60. * Converts the function into an asynchronous function. Each invocation of the resulting asynchronous function causes an invocation of the original synchronous function on the specified scheduler.
  61. * @param {Function} function Function to convert to an asynchronous function.
  62. * @param {Scheduler} [scheduler] Scheduler to run the function on. If not specified, defaults to Scheduler.timeout.
  63. * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
  64. * @returns {Function} Asynchronous function.
  65. */
  66. toAsync<T1, T2, T3, T4, TResult>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => TResult, context?: any, scheduler?: IScheduler): (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Observable<TResult>;
  67. }
  68. export interface ObservableStatic {
  69. /**
  70. * Converts a callback function to an observable sequence.
  71. *
  72. * @param {Function} function Function with a callback as the last parameter to convert to an Observable sequence.
  73. * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
  74. * @param {Function} [selector] A selector which takes the arguments from the callback to produce a single item to yield on next.
  75. * @returns {Function} A function, when executed with the required parameters minus the callback, produces an Observable sequence with a single value of the arguments to the callback as an array.
  76. */
  77. fromCallback<TResult>(func: Function, context: any, selector: Function): (...args: any[]) => Observable<TResult>;
  78. /**
  79. * Converts a callback function to an observable sequence.
  80. *
  81. * @param {Function} function Function with a callback as the last parameter to convert to an Observable sequence.
  82. * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
  83. * @param {Function} [selector] A selector which takes the arguments from the callback to produce a single item to yield on next.
  84. * @returns {Function} A function, when executed with the required parameters minus the callback, produces an Observable sequence with a single value of the arguments to the callback as an array.
  85. */
  86. fromCallback<TResult, T1>(func: (arg1: T1, callback: (result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1) => Observable<TResult>;
  87. /**
  88. * Converts a callback function to an observable sequence.
  89. *
  90. * @param {Function} function Function with a callback as the last parameter to convert to an Observable sequence.
  91. * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
  92. * @param {Function} [selector] A selector which takes the arguments from the callback to produce a single item to yield on next.
  93. * @returns {Function} A function, when executed with the required parameters minus the callback, produces an Observable sequence with a single value of the arguments to the callback as an array.
  94. */
  95. fromCallback<TResult, T1, T2>(func: (arg1: T1, arg2: T2, callback: (result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2) => Observable<TResult>;
  96. /**
  97. * Converts a callback function to an observable sequence.
  98. *
  99. * @param {Function} function Function with a callback as the last parameter to convert to an Observable sequence.
  100. * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
  101. * @param {Function} [selector] A selector which takes the arguments from the callback to produce a single item to yield on next.
  102. * @returns {Function} A function, when executed with the required parameters minus the callback, produces an Observable sequence with a single value of the arguments to the callback as an array.
  103. */
  104. fromCallback<TResult, T1, T2, T3>(func: (arg1: T1, arg2: T2, arg3: T3, callback: (result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2, arg3: T3) => Observable<TResult>;
  105. /**
  106. * Converts a callback function to an observable sequence.
  107. *
  108. * @param {Function} function Function with a callback as the last parameter to convert to an Observable sequence.
  109. * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
  110. * @param {Function} [selector] A selector which takes the arguments from the callback to produce a single item to yield on next.
  111. * @returns {Function} A function, when executed with the required parameters minus the callback, produces an Observable sequence with a single value of the arguments to the callback as an array.
  112. */
  113. fromCallback<TResult, T1, T2, T3, T4>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Observable<TResult>;
  114. /**
  115. * Converts a callback function to an observable sequence.
  116. *
  117. * @param {Function} function Function with a callback as the last parameter to convert to an Observable sequence.
  118. * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
  119. * @param {Function} [selector] A selector which takes the arguments from the callback to produce a single item to yield on next.
  120. * @returns {Function} A function, when executed with the required parameters minus the callback, produces an Observable sequence with a single value of the arguments to the callback as an array.
  121. */
  122. fromCallback<TResult, T1, T2, T3, T4, T5>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Observable<TResult>;
  123. /**
  124. * Converts a callback function to an observable sequence.
  125. *
  126. * @param {Function} function Function with a callback as the last parameter to convert to an Observable sequence.
  127. * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
  128. * @param {Function} [selector] A selector which takes the arguments from the callback to produce a single item to yield on next.
  129. * @returns {Function} A function, when executed with the required parameters minus the callback, produces an Observable sequence with a single value of the arguments to the callback as an array.
  130. */
  131. fromCallback<TResult, T1, T2, T3, T4, T5, T6>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, callback: (result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6) => Observable<TResult>;
  132. /**
  133. * Converts a callback function to an observable sequence.
  134. *
  135. * @param {Function} function Function with a callback as the last parameter to convert to an Observable sequence.
  136. * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
  137. * @param {Function} [selector] A selector which takes the arguments from the callback to produce a single item to yield on next.
  138. * @returns {Function} A function, when executed with the required parameters minus the callback, produces an Observable sequence with a single value of the arguments to the callback as an array.
  139. */
  140. fromCallback<TResult, T1, T2, T3, T4, T5, T6, T7>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7, callback: (result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7) => Observable<TResult>;
  141. /**
  142. * Converts a callback function to an observable sequence.
  143. *
  144. * @param {Function} function Function with a callback as the last parameter to convert to an Observable sequence.
  145. * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
  146. * @param {Function} [selector] A selector which takes the arguments from the callback to produce a single item to yield on next.
  147. * @returns {Function} A function, when executed with the required parameters minus the callback, produces an Observable sequence with a single value of the arguments to the callback as an array.
  148. */
  149. fromCallback<TResult, T1, T2, T3, T4, T5, T6, T7, T8>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7, arg8: T8, callback: (result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7, arg8: T8) => Observable<TResult>;
  150. /**
  151. * Converts a callback function to an observable sequence.
  152. *
  153. * @param {Function} function Function with a callback as the last parameter to convert to an Observable sequence.
  154. * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
  155. * @param {Function} [selector] A selector which takes the arguments from the callback to produce a single item to yield on next.
  156. * @returns {Function} A function, when executed with the required parameters minus the callback, produces an Observable sequence with a single value of the arguments to the callback as an array.
  157. */
  158. fromCallback<TResult, T1, T2, T3, T4, T5, T6, T7, T8, T9>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7, arg8: T8, arg9: T9, callback: (result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7, arg8: T8, arg9: T9) => Observable<TResult>;
  159. }
  160. export interface ObservableStatic {
  161. /**
  162. * Converts a Node.js callback style function to an observable sequence. This must be in function (err, ...) format.
  163. * @param {Function} func The function to call
  164. * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
  165. * @param {Function} [selector] A selector which takes the arguments from the callback minus the error to produce a single item to yield on next.
  166. * @returns {Function} An async function which when applied, returns an observable sequence with the callback arguments as an array.
  167. */
  168. fromNodeCallback<TResult>(func: Function, context?: any, selector?: Function): (...args: any[]) => Observable<TResult>;
  169. /**
  170. * Converts a Node.js callback style function to an observable sequence. This must be in function (err, ...) format.
  171. * @param {Function} func The function to call
  172. * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
  173. * @param {Function} [selector] A selector which takes the arguments from the callback minus the error to produce a single item to yield on next.
  174. * @returns {Function} An async function which when applied, returns an observable sequence with the callback arguments as an array.
  175. */
  176. fromNodeCallback<TResult, T1>(func: (arg1: T1, callback: (err: any, result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1) => Observable<TResult>;
  177. /**
  178. * Converts a Node.js callback style function to an observable sequence. This must be in function (err, ...) format.
  179. * @param {Function} func The function to call
  180. * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
  181. * @param {Function} [selector] A selector which takes the arguments from the callback minus the error to produce a single item to yield on next.
  182. * @returns {Function} An async function which when applied, returns an observable sequence with the callback arguments as an array.
  183. */
  184. fromNodeCallback<TResult, T1, T2>(func: (arg1: T1, arg2: T2, callback: (err: any, result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2) => Observable<TResult>;
  185. /**
  186. * Converts a Node.js callback style function to an observable sequence. This must be in function (err, ...) format.
  187. * @param {Function} func The function to call
  188. * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
  189. * @param {Function} [selector] A selector which takes the arguments from the callback minus the error to produce a single item to yield on next.
  190. * @returns {Function} An async function which when applied, returns an observable sequence with the callback arguments as an array.
  191. */
  192. fromNodeCallback<TResult, T1, T2, T3>(func: (arg1: T1, arg2: T2, arg3: T3, callback: (err: any, result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2, arg3: T3) => Observable<TResult>;
  193. /**
  194. * Converts a Node.js callback style function to an observable sequence. This must be in function (err, ...) format.
  195. * @param {Function} func The function to call
  196. * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
  197. * @param {Function} [selector] A selector which takes the arguments from the callback minus the error to produce a single item to yield on next.
  198. * @returns {Function} An async function which when applied, returns an observable sequence with the callback arguments as an array.
  199. */
  200. fromNodeCallback<TResult, T1, T2, T3, T4>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err: any, result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Observable<TResult>;
  201. /**
  202. * Converts a Node.js callback style function to an observable sequence. This must be in function (err, ...) format.
  203. * @param {Function} func The function to call
  204. * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
  205. * @param {Function} [selector] A selector which takes the arguments from the callback minus the error to produce a single item to yield on next.
  206. * @returns {Function} An async function which when applied, returns an observable sequence with the callback arguments as an array.
  207. */
  208. fromNodeCallback<TResult, T1, T2, T3, T4, T5>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err: any, result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Observable<TResult>;
  209. /**
  210. * Converts a Node.js callback style function to an observable sequence. This must be in function (err, ...) format.
  211. * @param {Function} func The function to call
  212. * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
  213. * @param {Function} [selector] A selector which takes the arguments from the callback minus the error to produce a single item to yield on next.
  214. * @returns {Function} An async function which when applied, returns an observable sequence with the callback arguments as an array.
  215. */
  216. fromNodeCallback<TResult, T1, T2, T3, T4, T5, T6>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, callback: (err: any, result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6) => Observable<TResult>;
  217. /**
  218. * Converts a Node.js callback style function to an observable sequence. This must be in function (err, ...) format.
  219. * @param {Function} func The function to call
  220. * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
  221. * @param {Function} [selector] A selector which takes the arguments from the callback minus the error to produce a single item to yield on next.
  222. * @returns {Function} An async function which when applied, returns an observable sequence with the callback arguments as an array.
  223. */
  224. fromNodeCallback<TResult, T1, T2, T3, T4, T5, T6, T7>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7, callback: (err: any, result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7) => Observable<TResult>;
  225. /**
  226. * Converts a Node.js callback style function to an observable sequence. This must be in function (err, ...) format.
  227. * @param {Function} func The function to call
  228. * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
  229. * @param {Function} [selector] A selector which takes the arguments from the callback minus the error to produce a single item to yield on next.
  230. * @returns {Function} An async function which when applied, returns an observable sequence with the callback arguments as an array.
  231. */
  232. fromNodeCallback<TResult, T1, T2, T3, T4, T5, T6, T7, T8>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7, arg8: T8, callback: (err: any, result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7, arg8: T8) => Observable<TResult>;
  233. /**
  234. * Converts a Node.js callback style function to an observable sequence. This must be in function (err, ...) format.
  235. * @param {Function} func The function to call
  236. * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
  237. * @param {Function} [selector] A selector which takes the arguments from the callback minus the error to produce a single item to yield on next.
  238. * @returns {Function} An async function which when applied, returns an observable sequence with the callback arguments as an array.
  239. */
  240. fromNodeCallback<TResult, T1, T2, T3, T4, T5, T6, T7, T8, T9>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7, arg8: T8, arg9: T9, callback: (err: any, result: TResult) => any) => any, context?: any, selector?: Function): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7, arg8: T8, arg9: T9) => Observable<TResult>;
  241. }
  242. export interface ObservableStatic {
  243. /**
  244. * Creates an observable sequence by adding an event listener to the matching DOMElement or each item in the NodeList.
  245. * @param {Object} element The DOMElement or NodeList to attach a listener.
  246. * @param {String} eventName The event name to attach the observable sequence.
  247. * @param {Function} [selector] A selector which takes the arguments from the event handler to produce a single item to yield on next.
  248. * @returns {Observable} An observable sequence of events from the specified element and the specified event.
  249. */
  250. fromEvent<T>(element: EventTarget, eventName: string, selector?: (arguments: any[]) => T): Observable<T>;
  251. /**
  252. * Creates an observable sequence by adding an event listener to the matching DOMElement or each item in the NodeList.
  253. * @param {Object} element The DOMElement or NodeList to attach a listener.
  254. * @param {String} eventName The event name to attach the observable sequence.
  255. * @param {Function} [selector] A selector which takes the arguments from the event handler to produce a single item to yield on next.
  256. * @returns {Observable} An observable sequence of events from the specified element and the specified event.
  257. */
  258. fromEvent<T>(element: { on: (name: string, cb: (e: any) => any) => void; off: (name: string, cb: (e: any) => any) => void }, eventName: string, selector?: (arguments: any[]) => T): Observable<T>;
  259. }
  260. export interface ObservableStatic {
  261. /**
  262. * Creates an observable sequence from an event emitter via an addHandler/removeHandler pair.
  263. * @param {Function} addHandler The function to add a handler to the emitter.
  264. * @param {Function} [removeHandler] The optional function to remove a handler from an emitter.
  265. * @param {Function} [selector] A selector which takes the arguments from the event handler to produce a single item to yield on next.
  266. * @returns {Observable} An observable sequence which wraps an event from an event emitter
  267. */
  268. fromEventPattern<T>(addHandler: (handler: Function) => void, removeHandler: (handler: Function) => void, selector?: (arguments: any[]) => T): Observable<T>;
  269. }
  270. export interface ObservableStatic {
  271. /**
  272. * Invokes the asynchronous function, surfacing the result through an observable sequence.
  273. * @param {Function} functionAsync Asynchronous function which returns a Promise to run.
  274. * @returns {Observable} An observable sequence exposing the function's result value, or an exception.
  275. */
  276. startAsync<T>(functionAsync: () => IPromise<T>): Observable<T>;
  277. }
  278. }
  279. declare module "rx.async" { export = Rx; }