Skip to content

potch/promise.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

promise.js is no longer under active development!

jarchibald/ES6-Promises does everything this library was set out to do.

promise.js

Promises/A+ 1.0 compliant

A Minimal, fully Promises/A+ compliant library.

Promises/A+ spec here: http://promisesaplus.com/

Build Status

Usage

  • promise() - Creates a promise. Can pass an optional obj argument. If passed, promise methods are attached to passed object.
  • promise.isPromise(obj) - Uses duck-typing to check whether the given object is a 'promise' (does it have a then method?)
  • promise.avow(fn) - wrap a function in a promise. Use like so:
var add = promise.avow(function (fulfill, reject, a, b) {
  if (a <= 2 && b <= 2) {
    fulfill(a + b);
  } else {
    reject('Math is hard.');
  }
});
add(1, 1).then(console.log);

Promise Methods

  • then(onFulfill, onReject) - bind fulfillment/rejection handlers to the promise. Returns a promise object
  • fulfill(value) - fulfills the promise with the passed value.
  • reject(reason) - rejects the promise with the passed reason.

For all behaviors, see the spec.

About

No longer under active development!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published