# p-wait-all

> `Promise.all`, but it waits for all promises to settle even if one of them rejected

Latest version **1.0.1** (published 2018-02-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install p-wait-all
pnpm add p-wait-all
yarn add p-wait-all
bun add p-wait-all
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2018-02-13 |
| First published | 2018-02-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 15 |
| Author | Renée Kooi |
| Maintainers | goto-bus-stop |
| Keywords | promise |

## Links

- npm: https://www.npmjs.com/package/p-wait-all
- Repository: https://github.com/goto-bus-stop/p-wait-all
- Homepage: https://github.com/goto-bus-stop/p-wait-all#readme
- Issues: https://github.com/goto-bus-stop/p-wait-all/issues
- npm.io page: https://npm.io/package/p-wait-all

## 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) — 2018-02-13
- 1.0.0 — 2018-02-06

## README

# p-wait-all

`Promise.all`, but it waits for all promises to settle even if one of them rejected.

## Installation

With npm:

```bash
npm install --save p-wait-all
```

## Usage

```js
var waitAll = require('p-wait-all')

var settled = false
var result = waitAll([
  Promise.reject(new Error('operation failed')),
  delay(200).then(function () { settled = true })
])

result.catch(function (err) {
  // rejected after 200ms;
  // settled === true
})
```

Compare doing this with `Promise.all`:

```js
var settled = false
var result = Promise.all([
  Promise.reject(new Error('operation failed')),
  delay(200).then(function () { settled = true })
])

result.catch(function (err) {
  // rejected immediately;
  // settled === false
})
```

This behaviour is useful if you are doing two async operations that may fail individually, so that both operations need to be rolled back.

For example, saving two related mongoose models, where one may fail (eg. from duplicate key errors):

```js
waitAll([
  model1.save(),
  relatedModel.save()
]).catch(function (err) {
  var p = []
  if (!model1.isNew) p.push(model1.remove())
  if (!relatedModel.isNew) p.push(relatedModel.remove())
  return Promise.all(p)
})
```

You cannot remove a model if it is still in the process of being saved, so you have to wait for all the `save()` promises to resolve before attempting to roll them back.

## API

### result = require('p-wait-all')(promises)

Wait for `promises` to settle. If any of them errored, reject the `result` promise with the error. If all of them resolved, resolve `result` with an array of resolution values, in order.

## License

[MIT](./LICENSE)

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