Skip to content
/ p-any Public
forked from sindresorhus/p-any

Wait for any promise to be fulfilled

License

Notifications You must be signed in to change notification settings

athese6/p-any

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

p-any Build Status

Wait for any promise to be fulfilled

Useful when you need the fastest promise.

You probably want this instead of Promise.race(). Reason.

Install

$ npm install --save p-any

Usage

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

API

pAny(input)

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.

input

Type: Iterable<Promise|any>

pAny.AggregateError

Exposed for instance checking.

Related

  • 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…

License

MIT © Sindre Sorhus

About

Wait for any promise to be fulfilled

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%