promise-polyfill-browserify v3.1.0
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.
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
Browser Support
IE8+, Chrome, Firefox, IOS 4+, Safari 5+, Opera
Downloads
Node
npm install promise-polyfillBower
bower install promise-polyfillSimple 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 (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._setImmediateFn(immedateFn) it will be used instead of window.setTimeout
npm install setasap --savevar Promise = require('promise-polyfill');
var setAsap = require('setasap');
Promise._setImmedateFn(setAsap);Testing
npm install
npm testLicense
MIT
10 years ago