Useful async functions
$ npm install async-tools
forEachSync(list, cb, fin)
Calls a callback for each item in a list after one another
list
: An array of values to be passed into the callbackcb
: The callback function called with each list itemfin
: The callback function called at the endforEachSyncCallback(item, next, fin)
item
: The item at the current iteration of the loopnext
: The callback function called to advance the loopfin
: The callback function called to end the loop earlyforEach(list, cb, fin)
Calls a callback for each item in a list at the same time
list
: An array of values to be passed into the callbackcb
: The callback function called with each list itemfin
: The callback function called at the end with error BooleanforEachCallback(item, done)
item
: The item at the current iteration of the loopdone
: The callback function called to end the current iteration with optional error BooleanwhileSync(cb, fin)
Calls a callback repeatedly until a condition is met
cb
: The callback function called to get the condition valuefin
: The callback function called at the endwhileSyncCallback(next)
next
: The callback function called with the condition value to advance the loopforEachFunctionSync(funcs, fin)
Calls functions in a list after one another
funcs
: An array of functions (forEachFunctionSyncCallback
) to be calledfin
: The callback function called at the endforEachFunctionSyncCallback(next, fin)
next
: The callback function called to advance the loopfin
: The callback function called to end the loop earlyforEachFunction(funcs, fin)
Calls functions in a list at the same time
funcs
: An array of functions (forEachFunctionCallback
) to be calledfin
: The callback function called at the end with error BooleanforEachFunctionCallback(done)
done
: The callback function called to end the current iteration with optional error Booleanwait(cond, cb, dur)
Blocks until a condition is met
cond
: The condition function - returns True when condition is metcb
: The callback function called when the condition is metdur
: Duration between condition checks - default 500mssyncFuncLoop(func)
Promise like interface to forEachFunctionSync
func
: The initial callback function to runthen
(syncFuncLoopCallback): Register a method to be called after next()
finally
(Function): Register a method to be called at the end with error message parametersyncFuncLoopCallback(next, fin)
next
: The callback function called to advance the loopfin
: The callback function called to end the loop early with optional error message parameterrun(func)
Return new instance of syncFuncLoop
func
: The initial callback function to runyour-great-feature
.See the LICENSE file.