Async.coffee
A CoffeeScript DSL for Async.
npm install async.coffee
In Action
asyncparallel -> @fn : -> setTimeout => @callback null1 500 @fn : -> setTimeout => @callback null2 200 @callback -> expect@resultsonetoBe 1 expect@resultstwotoBe 2 expect@errtoBeUndefined
Concepts
-
async functions have
@callback
in their context, also aliased as@cb
and@c
. They also receive it as their first argument. -
The
@callback
function receives the results as@results
, also aliased to@res
and@response
and the error as@err
,@e
or@error
. It also receives them as arguments:(err, res) ->
.
Supported Functions
- Parallel
- Map
Parallel
@fn
- receives an object of named functions.@callback
- (optional) the callback function.
asyncparallel -> @fn : -> setTimeout => @callback null1 500 @fn : -> setTimeout => @callback null2 200 @callback -> expect@resultsonetoBe 1 expect@resultstwotoBe 2 expect@errtoBeUndefined
Map (array, function)
@iter
- receives an object of named functions.@callback
- (optional) the callback function.
asyncmap 1..100-> @iter -> setTimeout => @callback null@item*2 100 @callback -> for i in 0...100 expect@resultsitoBei+1*2 expect@errtoBeUndefined done