Fork listen.js on GitHub

Listen.js is an open source JavaScript library that makes it easy to wait for mutliple Node-style callbacks and process the results

Install for Node with npm

npm install listen

Download for browsers

Standalone browser package can be downloaded here.

You can also use npm and bundle it with your application using Browserify.

Usage

var listen = require('listen');

var listener = listen();

var callbackA = listener();
var callbackB = listener();

/*
 * Do async stuff with callbacks.
 *
 * Callbacks follow the Node.js convention. They expect an error or null as
 * the first argument and an optional value as the second:
 *
 * Fail: callback(new Error('ouch!'));
 * Return: callback(null, 'some return value');
 */

listener.then(function (err, values) {
  /*
   * err    - 1) null if no callback err'd
   *          2) the error of the callback that err'd
   *          3) an error with name ErrorList wrapping multiple errors
   *
   * values - The non-undefined return values from all callbacks in order of
   *          callback creation
   */
});

Resources