# p-any

> Wait for any promise to be fulfilled

Latest version **4.0.0** (published 2021-05-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install p-any
pnpm add p-any
yarn add p-any
bun add p-any
```

## Health

**Score 28/100 (F)** — status: abandoned.

Positive: has types package; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2021-05-31 |
| First published | 2016-10-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/p-any) |
| Module format | ESM |
| Node | >=12.20 |
| Dependencies | 2 |
| Unpacked size | 5.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 56 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | promise, any, resolved, wait, collection, iterable, iterator, race, fulfilled, fastest, one, single, async, await, promises, bluebird |

## Links

- npm: https://www.npmjs.com/package/p-any
- Repository: https://github.com/sindresorhus/p-any
- Homepage: https://github.com/sindresorhus/p-any#readme
- Issues: https://github.com/sindresorhus/p-any/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/p-any

## Dependencies (2)

- [p-some](https://npm.io/package/p-some.md) ^6.0.0
- [p-cancelable](https://npm.io/package/p-cancelable.md) ^3.0.0

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 4.0.0 (latest) — 2021-05-31
- 3.0.0 — 2020-02-22
- 2.1.0 — 2019-04-04
- 2.0.0 — 2019-03-14
- 1.1.0 — 2017-06-13
- 1.0.0 — 2016-10-21

## README

# p-any

> Wait for any promise to be fulfilled

Useful when you need the fastest promise.

You probably want this instead of `Promise.race()`. [Reason.](http://bluebirdjs.com/docs/api/promise.race.html)

*With [Node.js 15](https://medium.com/@nodejs/node-js-v15-0-0-is-here-deb00750f278), there's now a built-in [`Promise#any`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any) method. The benefit of this package is that it has cancellation functionality.*

## Install

```
$ npm install p-any
```

## Usage

Checks 3 websites and logs the fastest.

```js
import pAny from 'p-any';
import got from 'got';

const first = await pAny([
	got.head('https://github.com').then(() => 'github'),
	got.head('https://google.com').then(() => 'google'),
	got.head('https://twitter.com').then(() => 'twitter'),
]);

console.log(first);
//=> 'google'
```

## API

### pAny(input, options?)

Returns a [cancelable `Promise`](https://github.com/sindresorhus/p-cancelable) that is fulfilled when any promise from `input` is fulfilled. If all the `input` promises reject, it will reject with an [`AggregateError`](https://github.com/sindresorhus/aggregate-error) error.

#### input

Type: `Iterable<Promise | unknown>`

#### options

Type: `object`

##### filter

Type: `Function`

Receives the value resolved by the promise. Used to filter out values that doesn't satisfy a condition.

### AggregateError

Exposed for instance checking.

## Related

- [p-some](https://github.com/sindresorhus/p-some) - Wait for a specified number of promises to be fulfilled
- [p-locate](https://github.com/sindresorhus/p-locate) - Get the first fulfilled promise that satisfies the provided testing function
- [More…](https://github.com/sindresorhus/promise-fun)

---
_Source: https://npm.io/package/p-any · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
