Infinity
Control flow to use a function whats is called infinity times. nodejs > 7 is required.
Install
$ npm install infinity-node --save
Usage
// callback examplesconst infinity = const assert = let counter = 0; let { if counter>10 counter++ // example 2 async { let counter = 0 { if counter>10 counter++ } let res = await } // example 3, the stop is not called if next is called beforeasync { let counter = 0 { if counter>10 counter++ } let res = await // example 4, the next is not called if stop is called beforeasync { let counter = 0 { if counter>10 counter++ } let res = await }// example 5, pass all argumentsasync { let counter = 0 { if counter>10 counter++ } let res = await }// example 6 if return a promise, wait until promise is resolved or rejectedasync { let counter = 0 { if counter>10 counter++ return Promise } infinityasync = false let res = await }// example 6.1async { { return Promise } await }// catch any error throwasync { { throw 'error thrown' } await }}
infinity-node(callback[, arg1, arg2, ...])-> Promise
The first time callback function is called with three arguments arg, next and stop given when the infinity function is called. This function return a promise.
next([object])
The arg passed to this callback is passed like third param to callback in infinity. If next is not called in callback and async property in infinity is false, then next is called when callback is done with the returned valued. When a promise is passed to next, the loop is called again until the promise is resolved.
stop([error,value])
When is called the loop is stopped. If error is different to null then the promise returned by infinity is rejected. In otherwise the promise is resolved with value given.