# p-try-each

> Runs promise-returning functions in series but stops whenever any of the functions were successful

Latest version **1.0.1** (published 2019-10-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install p-try-each
pnpm add p-try-each
yarn add p-try-each
bun add p-try-each
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2019-10-14 |
| First published | 2019-10-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | pedromiguelss |
| Keywords | sequential, promises, promise, series, async, await, array, tasks |

## Links

- npm: https://www.npmjs.com/package/p-try-each
- Repository: https://github.com/PedroMiguelSS/p-try-each
- Homepage: https://github.com/PedroMiguelSS/p-try-each#readme
- Issues: https://github.com/PedroMiguelSS/p-try-each/issues
- npm.io page: https://npm.io/package/p-try-each

## 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

- 1.0.1 (latest) — 2019-10-14
- 1.0.0 — 2019-10-13

## README

# p-try-each [![Build Status](https://travis-ci.org/PedroMiguelSS/p-try-each.svg?branch=master)](https://travis-ci.org/PedroMiguelSS/p-try-each)

> Runs promise-returning functions in series but stops whenever any of the functions were successful. If all functions reject, the promise will be rejected with the error of the final task

Similar to [`async/tryEach`](https://caolan.github.io/async/v3/docs.html#tryEach).

## Install

```
npm install --save p-try-each
```

## Usage

```js
const pTryEach = require('p-try-each');

const tasks = [
  () => Promise.resolve('foo'),
  () => Promise.resolve('bar'),
  () => Promise.resolve('baz')
]

(async () => {
  const res = await pTryEach(tasks);
  console.log(res);
  // Logs:
  // 'foo'
})();
```

## API

### pTryEach(tasks)

Returns a `Promise` that is fulfilled with the value of the first fulfilled promise returned from calling the functions in `tasks`. If none is fulfilled, the promise will be rejected with the error of the final task.

#### tasks

Type: `Iterable<Function>`

Functions must return a value. In case of a returned promise, it will be awaited before starting with the next task.

## License

MIT

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