Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

85 lines (52 sloc) 3.055 kB

when.js Build Status

A lightweight CommonJS Promises/A and when() implementation. It also provides several other useful Promise-related concepts, such as joining and chaining, and has a robust unit test suite.

It's just over 1k when compiled with Google Closure (w/advanced optimizations) and gzipped.

when.js was derived from the async core of wire.js.

What's New?


  • Create a resolved promise: when.resolve(value) creates a resolved promise for value. See API docs.
  • Resolve/reject return something useful: deferred.resolve and deferred.reject now return a promise for the fulfilled or rejected value.
  • Resolve a deferred with another promise: deferred.resolve(promise) - when promise resolves or rejects, so will deferred.

Full Changelog

Docs & Examples

API docs

More info on the wiki


Quick Start


  1. git clone or git submodule add
  2. Configure your loader with a package:

    packages: [
        { name: 'when', location: 'path/to/when/', main: 'when' },
        // ... other packages ...
  3. define(['when', ...], function(when, ...) { ... }); or require(['when', ...], function(when, ...) { ... });

Script Tag

  1. git clone or git submodule add
  2. <script src="path/to/when/when.js"></script>
  3. when will be available as window.when


  1. npm install when
  2. var when = require('when');


  1. ringo-admin install cujojs/when
  2. var when = require('when');

Running the Unit Tests

Install buster.js

npm install -g buster

Run unit tests in Node:

  1. buster test -e node

Run unit tests in Browsers (and Node):

  1. buster server - this will print a url
  2. Point browsers at /capture, e.g. localhost:1111/capture
  3. buster test or buster test -e browser


Much of this code was inspired by @unscriptable's tiny promises, the async innards of wire.js, and some gists here, here, here, and here

Some of the code has been influenced by the great work in Q, Dojo's Deferred, and uber.js.

Jump to Line
Something went wrong with that request. Please try again.