cloudcmd/modules/promise-polyfill
2015-03-28 09:16:49 -04:00
..
.bower.json feature(modules) add 2015-03-28 09:16:49 -04:00
bower.json feature(modules) add 2015-03-28 09:16:49 -04:00
Gruntfile.js feature(modules) add 2015-03-28 09:16:49 -04:00
LICENSE feature(modules) add 2015-03-28 09:16:49 -04:00
package.json feature(modules) add 2015-03-28 09:16:49 -04:00
Promise.js feature(modules) add 2015-03-28 09:16:49 -04:00
Promise.min.js feature(modules) add 2015-03-28 09:16:49 -04:00
README.md feature(modules) add 2015-03-28 09:16:49 -04:00

Promises/A+ logo Promise [![Build Status](https://travis-ci.org/taylorhakes/promise-polyfill.png?branch=master)](https://travis-ci.org/taylorhakes/promise-polyfill) =============

Lightweight promise polyfill for the browser and node. A+ Compliant. It is a perfect polyfill IE, Firefox or any other browser that does not support native promises.

This implementation is based on then/promise. It has been changed to use the prototype for performance and memory reasons.

For API information about Promises, please check out this article HTML5Rocks article.

It is extremely lightweight. < 1kb Gzipped

Downloads

Node

npm install promise-polyfill

Simple use

var prom = new Promise(function(resolve, reject) {
  // do a thing, possibly async, then…

  if (/* everything turned out fine */) {
    resolve("Stuff worked!");
  }
  else {
    reject(new Error("It broke"));
  }
});

// Do something when async done
prom.then(function() {
  ...
});

Performance

By default promise-polyfill uses setImmediate, but falls back to setTimeout for executing asynchronously. If a browser does not support setImmediate, you may see performance issues. Use a setImmediate polyfill to fix this issue. setAsap or setImmediate work well.

Testing

npm install
npm test

License

MIT