Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Implementation of Promises/A+
JavaScript
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
src
test
.gitignore
.travis.yml
LICENSE
README.md
package.json

README.md

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?

Something went wrong with that request. Please try again.