Giter VIP home page Giter VIP logo

promise-ponyfill's Introduction

Deprecated

All reasonably modern platforms support native Promises, so this library is obsolete. Use the native Promise API instead.

promise-ponyfill

Preconfigured Promise ponyfill based on promise-polyfill and setasap.

A ponyfill is like a polyfill, but it does not alter the global namespace.

Why?

This ponyfill is based on promise-polyfill. Out of the box promise-polyfill implements Promise using setImmediate if available, and otherwise it falls back to setTimeout.

This leads to a significant performance degradation on platforms where neither Promise nor setImmediate are available natively. For optimal performance on these platforms it is necessary to configure promise-polyfill to use a setImmediate polyfill such as setasap.

This module preconfigures promise-polyfill to use setasap so you don't have to think about it. Just import this module and use it like a regular Promise.

Installation and usage

npm install --save promise-ponyfill
import Promise from "promise-ponyfill";

const promise = new Promise((resolve, reject) =>
                            setTimeout(resolve, 1000));

promise.then(value => console.log("Promise resolved."))
    .catch(reason => console.error("Promise rejected", reason));

If the platform provides a native implementation of Promise, then this module will simply return the native implementation.

This is a wilful violation of the usual philosophy of ponyfills, which advocate returning the polyfill implementation in all cases. I believe that this is the best choice in this case because native Promise provides better error reporting, and I am not aware of any platforms that provide a bad native Promise implementation. If you are aware of any please let me know by raising an issue.

Copyright

See LICENSE.md for copyright and licensing information pertaining to this module.

promise-polyfill and setasap have their own separate copyright and licensing terms. See the documentation for those modules.

promise-ponyfill's People

Contributors

dependabot[bot] avatar djcsdy avatar greenkeeper[bot] avatar renovate-bot avatar renovate[bot] avatar

Watchers

 avatar  avatar  avatar

promise-ponyfill's Issues

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.