Nascent Prototype Metaverse

    promise-any-polyfill
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.1 • Public • Published

    Promise.any Polyfill

    A polyfill for the Promise.any function.

    Find promise-any-polyfill on NPM.

    Table of Contents

    Installation

    Install from NPM with

    $ npm install --save promise-any-polyfill
    

    Basic Usage

    This package implements the upcoming Promise.any(...) functionality, and it can be used as follows:

    Promise.any([
        timedResolvingPromise(50, "what's up?"),
        timedResolvingPromise(25, "I'm quick!"),
        timedResolvingPromise(75, "I'm late!")
    ]).then((result: string): void => console.log(result)); //=> "I'm quick!"

    As you can see from the above example, Promise.any will resolve to the value of the first resolving Promise that was passed to the function`.

    If all promises reject, Promise.any will reject with an array of each of the rejection values from the Promises passed to the function.

    Promise.any([
        timedRejectingPromise(50, "...somewhere down the middle..."),
        timedRejectingPromise(25, "I failed first!"),
        timedRejectingPromise(75, "...at least I failed last!")
    ]).catch((error: string): void => console.error(error)); //=> ["I failed first!", "...somewhere down the middle...", "...at least I failed last!"]

    Promise.any will ignore any rejecting Promises so long as at least one of the Promises passed to the function resolves.

    Promise.any([
    	timedRejectingPromise(25, "I'm first, but I'm failing!"),
    	timedResolvingPromise(50, "I'm the only one resolving!"),
        timedRejectingPromise(75, "I'm last AND failing!")
    ]).then((result: string): void => console.log(result)); //=> "I'm the only one resolving!"

    Documentation

    See the wiki for full documentation.

    License

    promise-any-polyfill is made available under the GNU General Public License v3.

    Copyright (C) 2021 Trevor Sears

    Install

    npm i promise-any-polyfill

    DownloadsWeekly Downloads

    2,237

    Version

    1.0.1

    License

    GPL-3.0-or-later

    Unpacked Size

    43 kB

    Total Files

    10

    Last publish

    Collaborators

    • t99