Search

6/24/2013

caolan/async

caolan/async

Async is a utility module which provides straight-forward, powerful functions for working with asynchronous JavaScript. Although originally designed for use with node.js, it can also be used directly in the browser. Also supports component. Async provides around 20 functions that include the usual 'functional' suspects (map, reduce, filter, each…) as well as some common patterns for asynchronous control flow (parallel, series, waterfall…). All these functions assume you follow the node.js convention of providing a single callback as the last argument of your async function.
pow = (n, callback) ->
  setTimeout (->
    callback null, Math.pow(n, 5)
  ), Math.random()*10*1000

async.map([1, 2, 3], pow, (err, result) ->
  # log the result after all the async operation complete.
  console.log 'result', result
)

沒有留言: