Add definition and test for when.iterate

This commit is contained in:
Michael Nahkies
2015-09-03 12:00:45 +12:00
parent 04a025ada3
commit 8d071a6ee3
2 changed files with 29 additions and 0 deletions
+14
View File
@@ -127,6 +127,20 @@ declare module When {
*/
function settle<T>(promisesOrValues: any[]): Promise<Descriptor<T>[]>;
/**
* Generates a potentially infinite stream of promises by repeatedly calling f until predicate becomes true.
* @memberOf when
* @param f function that, given a seed, returns the next value or a promise for it.
* @param predicate function that receives the current iteration value, and should return truthy when the iterating should stop
* @param handler function that receives each value as it is produced by f. It may return a promise to delay the next iteration.
* @param seed initial value provided to the handler, and first f invocation. May be a promise.
*/
function iterate<U>(f: (seed: U) => U | Promise<U>,
predicate: (value: U) => boolean,
handler: (value: U) => Promise<any> | void,
seed: U | Promise<U>): Promise<U>;
/**
* Creates a {promise, resolver} pair, either or both of which
* may be given out safely to consumers.