Wait for any promise to be fulfilled
Useful when you need the fastest promise.
You probably want this instead of Promise.race(). Reason.
$ npm install --save p-any
Checks 3 websites and logs the fastest.
const got = require('got');
const pAny = require('p-any');
pAny([
got.head('github.com').then(() => 'github'),
got.head('google.com').then(() => 'google'),
got.head('twitter.com').then(() => 'twitter'),
]).then(first => {
console.log(first);
//=> 'google'
});Returns a Promise that is fulfilled when any promise from input is fulfilled. If all the input promises reject, it will reject with an AggregateError error.
Type: Iterable<Promise|any>
Exposed for instance checking.
- p-some - Wait for a specified number of promises to be fulfilled
- p-locate - Get the first fulfilled promise that satisfies the provided testing function
- More…
MIT © Sindre Sorhus