When.js is cujojs's lightweight CommonJS Promises/A and when()
implementation, derived from the async core of wire.js, cujojs's IOC Container. It also provides several other useful Promise-related concepts, such as joining multiple promises, mapping and reducing collections of promises, timed promises, and has a robust unit test suite.
It passes the Promises/A Test Suite, is frighteningly fast, and is under 1.3k when compiled with Google Closure (w/advanced optimizations) and gzipped, and has no dependencies.
- Removed leftover internal usages of
deferred.then
. - when/debug allows configuring the set of "fatal" error types that will be rethrown to the host env.
- DEPRECATED:
deferred.then
is deprecated and will be removed in an upcoming release. Usedeferred.promise.then
instead. - promise.yield(promiseOrValue) convenience API for substituting a new value into a promise chain.
- promise.spread(variadicFunction) convenience API for spreading an array onto a fulfill handler that accepts variadic arguments. Mmmm, buttery
- Doc improvements:
- when() and promise.then() have more info about callbacks and chaining behavior.
- More info and clarifications about the roles of Deferred and Resolver
- Several minor clarifications for various APIs
- Internal improvements to assimilation and interoperability with other promise implementations.
- Fix for accidental coercion of non-promises. See #62.
- New when.join - Joins 2 or more promises together into a single promise.
- when.some and when.any now act like competitive races, and have generally more useful behavior. Read the discussion in #60.
- Experimental progress event propagation. Progress events will propagate through promise chains. Read the details here.
- Temporarily removed calls to
Object.freeze
. Promises are no longer frozen due to a horrendous v8 performance penalty. Read discussion here.- IMPORTANT: Continue to treat promises as if they are frozen, since
freeze()
will be reintroduced once v8 performance improves.
- IMPORTANT: Continue to treat promises as if they are frozen, since
- when/debug now allows setting global a debugging callback for rejected promises.
-
git clone https://github.com/cujojs/when
orgit submodule add https://github.com/cujojs/when
-
Configure your loader with a package:
packages: [ { name: 'when', location: 'path/to/when/', main: 'when' }, // ... other packages ... ]
-
define(['when', ...], function(when, ...) { ... });
orrequire(['when', ...], function(when, ...) { ... });
git clone https://github.com/cujojs/when
orgit submodule add https://github.com/cujojs/when
<script src="path/to/when/when.js"></script>
when
will be available aswindow.when
npm install when
var when = require('when');
ringo-admin install cujojs/when
var when = require('when');
Note that when.js includes @domenic's Promises/A Test Suite. Running unit tests in Node will run both when.js's own test suite, and the Promises/A Test Suite.
npm install
npm test
npm install
npm start
- starts buster server & prints a url- Point browsers at /capture, e.g.
localhost:1111/capture
npm run-script test-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.