JSPM

  • Created
  • Published
  • Downloads 972751
  • Score
    100M100P100Q200147F

A lightweight Promises/A+ and when() implementation, plus other async goodies.

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

Promises/A+ logo

Build Status

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.

Quick Start

AMD

  1. Get it

    • bower install when or yeoman install when, or
    • git clone https://github.com/cujojs/when or git submodule add https://github.com/cujojs/when
  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, ...) { ... });

Node

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

RingoJS

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

Ender

  1. ender add cujojs/when
  2. var when = require('when');

Legacy environments (via browserify)

  1. git clone https://github.com/cujojs/when
  2. npm install
  3. npm run browserify to generate build/when.js
    1. Or npm run browserify-debug to build with when/monitor/console enabled
  4. <script src="path/to/when/build/when.js"></script>
    1. when will be available as window.when
    2. Other modules will be available as sub-objects/functions, e.g. window.when.fn.lift, window.when.sequence. See the full sub-namespace list in the browserify build file

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.

  1. npm install
  2. npm test

Browsers

  1. npm install
  2. npm start - starts buster server & prints a url
  3. Point browsers at /capture, e.g. localhost:1111/capture
  4. 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.