src/async/index.coffee |
|
|---|---|
A bunch of functions to deals with asynchronous process. Table Of Content |
|
parallel |
|
Execute an array of functions
|
parallel = (fns, callback) -> count = 0 results = [] cb = (res) -> count += 1 results.push(res) if count is fns.length then callback? results if fns.empty() then callback [] else fn cb for fn in fns |
queue |
|
Execute an array of functions
|
queue = (fns, callback) -> next = -> if fns.empty() then callback() else fns.shift() next next() |
chain |
|
Execute an array of functions
|
chain = (fns, args..., callback) -> next = (args...) -> if fns.empty() callback.apply null, args else fns.shift().apply null, args.concat next next.apply null, args module.exports = {queue, parallel, chain} |