promising

Implementation of [Promises/A+](http://promises-aplus.github.com/promises-spec/)

npm install promising
10 downloads in the last week
20 downloads in the last month

Implementation of Promises/A+

Build Status

Usage

Creating a promise

var promising = require('promising');

function myAsyncFunction() {
  var promise = promising();
  // do something...
  return promise;
}

Fulfilling a promise

function myAsyncFunction() {
  var promise = promising();
  setTimeout(function() {
    promise.fulfill(42);
  }, 2000);
  return promise;
}

Rejecting a promise

function myAsyncFunction() {
  var promise = promising();
  setTimeout(function() {
    promise.reject(24);
  }, 2000);
  return promise;
}

Most conveniently:

function myAsyncFunction() {
  return promising(function(promise) {
    promise.fulfill();
    // or
    promise.reject('foo');
    // or
    throw 'foo'; // <<< equals rejecting
  });
});

That's about it.

Who uses it?

npm loves you