cloudcmd/modules/promise-polyfill
2016-10-04 15:17:03 +03:00
..
.bower.json feature(bower) smalltalk v2.1.3 2016-10-04 15:17:03 +03:00
bower.json feature(bower) promise-polyfill v5.0.0 2016-05-04 11:27:33 +03:00
CHANGELOG.md feature(bower) promise-polyfill v6.0.2 2016-09-30 16:47:25 +03:00
karma.conf.js feature(bower) promise-polyfill v5.0.0 2016-05-04 11:27:33 +03:00
LICENSE feature(modules) add 2015-03-28 09:16:49 -04:00
package.json feature(bower) promise-polyfill v6.0.2 2016-09-30 16:47:25 +03:00
promise.js feature(bower) promise-polyfill v6.0.2 2016-09-30 16:47:25 +03:00
promise.min.js feature(bower) promise-polyfill v6.0.2 2016-09-30 16:47:25 +03:00
README.md feature(bower) promise-polyfil v6.0.0 2016-07-21 11:17:18 +03:00

Promises/A+ logo # Promise Polyfill [![travis][travis-image]][travis-url]

Lightweight ES6 Promise polyfill for the browser and node. Adheres closely to the spec. It is a perfect polyfill IE, Firefox or any other browser that does not support native promises.

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

It is extremely lightweight. < 1kb Gzipped

Browser Support

IE8+, Chrome, Firefox, IOS 4+, Safari 5+, Opera

NPM Use

npm install promise-polyfill --save-exact

Bower Use

bower install promise-polyfill

Downloads

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"));
  }
});

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

Deprecations

  • Promise._setImmediateFn(<immediateFn>) has been deprecated. Use Promise._immediateFn = <immediateFn>; instead.
  • Promise._setUnhandledRejectionFn(<rejectionFn>) has been deprecated. Use Promise._unhandledRejectionFn = <rejectionFn> instead. These functions will be removed in the next major version.

Performance

By default promise-polyfill uses setImmediate, but falls back to setTimeout for executing asynchronously. If a browser does not support setImmediate (IE/Edge are the only browsers with setImmediate), you may see performance issues. Use a setImmediate polyfill to fix this issue. setAsap or setImmediate work well.

If you polyfill window.setImmediate or use Promise._immediateFn = yourImmediateFn it will be used instead of window.setTimeout

npm install setasap --save
var Promise = require('promise-polyfill');
var setAsap = require('setasap');
Promise._immediateFn = setAsap;

Unhandled Rejections

promise-polyfill will warn you about possibly unhandled rejections. It will show a console warning if a Promise is rejected, but no .catch is used. You can turn off this behavior by setting Promise._setUnhandledRejectionFn(<rejectError>). If you would like to disable unhandled rejections. Use a noop like below.

Promise._unhandledRejectionFn = function(rejectError) {};

Testing

npm install
npm test

License

MIT