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 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>
Type: Object
Type: Function
Receives the value resolved by the promise. Used to filter out values that doesn't satisfy a condition.
Exposed for instance checking.
MIT © Sindre Sorhus