Package Exports
- when
- when/apply
- when/callbacks
- when/delay
- when/function
- when/guard
- when/keys
- when/monitor/aggregator
- when/monitor/console
- when/monitor/stackFilter
- when/monitor/throttledReporter
- 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 that powers the async core of wire.js, cujoJS's IOC Container. It features:
- A rock solid, battle-tested Promise implementation
- Resolving, settling, 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 and compact, and has no external dependencies.
What's New?
2.6.0
- New
promise.done
allows consuming the ultimate value at the end of a promise chain while ensuring that any errors are thrown to the host environment so you get loud stack traces. when/node/function
bindCallback
andliftCallback
now behave more like standard node-style APIs in that they allow exceptions to propagate to the host environment for loud stack traces.
2.5.1
ensure
now ignores non-functions, likethen
does, for consistency. (#207)
2.5.0
- Promises/A+ 1.1 compliant. Passes version 2.0.0 of the Promises/A+ test suite.
2.4.1
- New
MutationObserver
scheduler further reduces "time-to-first-handler" in modern browsers. (#198)- Also, this works around a horrible IE10 bug (desktop and mobile) that renders
setImmediate
,MessageChannel
, andpostMessage
unusable as fast task schedulers. Many thanks to @plaa and @calvinmetcalf for their help in discovering the problem and working out a solution. (#197)
- Also, this works around a horrible IE10 bug (desktop and mobile) that renders
2.4.0
- Experimental support for vert.x 2.x. Should now run in vert.x >= 1.1.0.
- New
when.isPromiseLike
as the more accurately-named synonym forwhen.isPromise
. - DEPRECATED:
when.isPromise
. It can only tell you that something is "promise-like" (aka "thenable") anyway. Use the new, more accurately-namedwhen.isPromiseLike
instead. - Fix for promise monitor reporting extra unhandled rejections for
when.all
andwhen.map
.
2.3.0
- New
promise.tap
for adding side effects to a promise chain. - New
MessageChannel
scheduler reduces "time-to-first" handler, in environments that support it. - Performance optimizations for promise resolution.
- Internal architecture improvements to pave the way for when.js 3.0.0.
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(); }; window.define.amd = {}; </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.