Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

CoffeeScript DSL for AsyncJS

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 dist
Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .npmignore
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 Cakefile
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.md
Octocat-spinner-32 index.js
Octocat-spinner-32 package.json
README.md

build status

Async.coffee

A CoffeeScript DSL for Async.

npm install async.coffee

In Action

async.parallel ->
    @fn one: ->
        setTimeout =>
                @callback null, 1
            , 500

    @fn two: ->
        setTimeout =>
                @callback null, 2
            , 200

    @callback ->
        expect(@results.one).toBe 1
        expect(@results.two).toBe 2
        expect(@err).toBeUndefined()

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.
async.parallel ->
    @fn one: ->
        setTimeout =>
                @callback null, 1
            , 500

    @fn two: ->
        setTimeout =>
                @callback null, 2
            , 200

    @callback ->
        expect(@results.one).toBe 1
        expect(@results.two).toBe 2
        expect(@err).toBeUndefined()

Map (array, function)

  • @iter - receives an object of named functions.
  • @callback - (optional) the callback function.
async.map [1..100], ->
    @iter ->
        setTimeout =>
                @callback null, @item*2
            , 100
    @callback ->
        for i in [0...100]
            expect(@results[i]).toBe((i+1)*2)
        expect(@err).toBeUndefined()
        done()
Something went wrong with that request. Please try again.