8.3.0 • Published 1 year ago

promise-polyfill v8.3.0

Weekly downloads
2,908,592
License
MIT
Repository
github
Last release
1 year ago

Promise Polyfill

Lightweight ES6 Promise polyfill for the browser and node. Adheres closely to the spec. It is a perfect polyfill IE 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

CDN Polyfill Use

This will set a global Promise object if the browser doesn't already have window.Promise.

<script src="https://cdn.jsdelivr.net/npm/promise-polyfill@8/dist/polyfill.min.js"></script>

Downloads

Simple use

If you would like to add a global Promise object (Node or Browser) if native Promise doesn't exist (polyfill Promise). Use the method below. This is useful if you are building a website and want to support older browsers. Javascript library authors should NOT use this method.

import 'promise-polyfill/src/polyfill';

If you would like to not affect the global environment (sometimes known as a ponyfill, you can import the base module. This is nice for library authors or people working in environment where you don't want to affect the global environment.

import Promise from 'promise-polyfill';

If using require with Webpack 2+ (rare), you need to specify the default import

var Promise = require('promise-polyfill').default;

then you can use like normal Promises

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

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
import Promise from 'promise-polyfill/src/polyfill';
import setAsap from '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 change this behavior by doing.

-NOTE: This only works on promise-polyfill Promises. Native Promises do not support this function

Promise._unhandledRejectionFn = <your reject error handler>;

If you would like to disable unhandled rejection messages. Use a noop like below.

Promise._unhandledRejectionFn = function(rejectError) {};

Testing

npm install
npm test

License

MIT

coveo-interface-editordci-webui@wizzn/auth0-ionic@quoyi/qqplayerjs-paymentseasy-local-storetommy_corechameleon-polyfills@deriv/traderwinc-tgoo-clientpc-renewalzhubajiedplayer-fork-lxmcustom-dashboard-coreve-playeraccess-vue-geetestimage2d.doc@amigocloud/js-client@pano.video/panortc-activexeviewer-lib@leptest/gatsby-netlify-cms@republicfinance/ui-component-library@vvni/aplayersrn-zip-formlauncher_v2@ikonintegration/braintree-web-drop-inaframe-sceneaframe-sesh3qinvideo-dplayersesh-aframesesh-aframe-kitsesh-aframe2sesh-aframe4sesh-aframe5scene-aframenodebb-theme-persona-viteowgrapesjsfiletape@opendoor/optimizely-sdkseamlesspay-web@coldstartai/auth0-spa-js@navvi/slashauth-react@navvi/slashauth-react-client@slashauth/slashauth-react-beta@sana-ru/provider-search-renderreact-clmtrackrprettyalertgrapesjs-vietsub@infinitebrahmanuniverse/nolb-promise-@livechat/chat-widgetids-enterpriseradiokit-toolkit-streaminggokul-kv-sdkgokul-sdk@everything-registry/sub-chunk-2481web-camera.jseviewer7-lib@mstechusa/eviewer7-clilapti-apihtml2pdf-easyamazon-ivs-playerangular-router-animations@angelsoft/react-form-validator-corehanafudahansa@ardatan/raml-1-parserangular_record_storeapexcharts-satosapexchartsfixedapi-language-serveranm-pa-query-websites@aquicore/auth0-spa-jshalu-mapgulp-tributary@apollopay/apollo-pay-jsguppy-component-reactapim-uiapp-banneraplayer-remakeaplayer2aplus-as-promisedaplayer@autheos/embedcode@authok/authok-spa-jsappauthhelperapiconnect-ui-buildappxgenapsmeearcadsappnexus-cmpargosyargosy-clientamor-grapesjs@zxfe/citic-cli-service@aaxis/auth0-spa-js@adobe/reactor-promiseactions-apiactions-admingrapesjs-clotgrapesjs
8.3.0

1 year ago

8.2.3

2 years ago

8.2.2

2 years ago

8.2.1

2 years ago

8.2.0

3 years ago

8.1.3

5 years ago

8.1.2

5 years ago

8.1.1

5 years ago

8.1.0

6 years ago

8.0.0

6 years ago

7.1.2

6 years ago

7.1.1

6 years ago

7.1.0

6 years ago

7.0.2

6 years ago

7.0.1

6 years ago

7.0.0

6 years ago

6.1.0

6 years ago

6.0.2

8 years ago

6.0.1

8 years ago

6.0.0

8 years ago

5.2.1

8 years ago

5.2.0

8 years ago

5.1.0

8 years ago

5.0.0

8 years ago

4.0.4

8 years ago

4.0.3

8 years ago

4.0.2

8 years ago

4.0.1

8 years ago

3.1.0

8 years ago

3.0.0

8 years ago

2.1.4

8 years ago

2.1.3

8 years ago

2.1.2

8 years ago

2.1.1

8 years ago

2.1.0

9 years ago

2.0.2

9 years ago

2.0.1

9 years ago

2.0.0

9 years ago

1.1.6

10 years ago

1.1.5

10 years ago

1.1.3

10 years ago

1.1.2

10 years ago

1.1.0

10 years ago

1.0.6

10 years ago

1.0.5

10 years ago

1.0.1

10 years ago