Package Exports
- when
- when/apply
- when/callbacks
- when/delay
- when/function
- when/keys
- when/node/function
- when/parallel
- when/pipeline
- when/poll
- when/sequence
- when/timeout
- when/unfold
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (when) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
when.js
When.js is cujojs's lightweight Promises/A+ and when()
implementation, derived from the async core of wire.js, cujojs's IOC Container. It features:
- A rock solid, battle-tested Promise implementation
- Resolving, mapping, and reducing arrays of promises
- Executing tasks in parallel and sequence
- Transforming Node-style and other callback-based APIs into promise-based APIs
It passes the Promises/A+ Test Suite, is very fast, is under 1.5k when compiled with Google Closure + gzip, and has no external dependencies.
What's New?
2.0.0
- Fully asynchronous resolutions.
- Promises/A+ compliance.
- New
when/keys
module withall()
andmap()
for object keys/values. - New
promise.ensure
as a better, and safer, replacement forpromise.always
. See discussion as to whypromise.always
is mistake-prone.- DEPRECATED:
promise.always
- DEPRECATED:
lift()
is now the preferred name for what wasbind()
in when/function, when/node/function, and when/callbacks.- DEPRECATED:
bind()
inwhen/function
,when/node/function
, andwhen/callbacks
. Uselift()
instead.
- DEPRECATED:
Docs & Examples
Quick Start
AMD
Get it
bower install when
oryeoman install when
, orgit 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, ...) { ... });
Node
npm install when
var when = require('when');
RingoJS
ringo-admin install cujojs/when
var when = require('when');
Legacy environments
git clone https://github.com/cujojs/when
orgit submodule add https://github.com/cujojs/when
Add a transient
define
shim, and a<script>
element for when.js<script> window.define = function(factory) { try{ delete window.define; } catch(e){ window.define = void 0; } // IE window.when = factory(); }; </script> <script src="path/to/when/when.js"></script>
when
will be available aswindow.when
Running the Unit Tests
Node
Note that when.js includes the 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
Browsers
npm install
npm start
- starts buster server & prints a url- Point browsers at
/capture, e.g. localhost:1111/capture
npm run-script test-browser
References
Much of this code was inspired by the async innards of wire.js, and has been influenced by the great work in Q, Dojo's Deferred, and uber.js.