# p-times

> Run promise-returning & async functions a specific number of times concurrently

Latest version **4.0.0** (published 2021-06-03) · MIT license · 0 weekly downloads

## Install

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

## 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-06-03 |
| First published | 2016-10-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/p-times) |
| Module format | ESM |
| Node | >=12.20 |
| Dependencies | 1 |
| Unpacked size | 4.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 42 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | promise, times, number, count, loop, iterate, async, await, promises, concurrently, concurrency, parallel, bluebird |

## Links

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

## Dependencies (1)

- [p-map](https://npm.io/package/p-map.md) ^5.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-06-03
- 3.0.0 — 2020-04-24
- 2.1.0 — 2019-04-03
- 2.0.0 — 2019-03-16
- 1.0.1 — 2016-10-28
- 1.0.0 — 2016-10-22

## README

# p-times

> Run promise-returning & async functions a specific number of times concurrently

## Install

```
$ npm install p-times
```

## Usage

```js
import pTimes from 'p-times';

const result = await pTimes(5, index => createFixture(`🦄-${index + 1}`));

console.log(`Created fixtures: ${result.join(' ')}`);
//=> 'Created fixtures: 🦄-1 🦄-2 🦄-3 🦄-4 🦄-5'
```

## API

### pTimes(count, mapper, options?)

Returns a `Promise` that is fulfilled when all promises returned from `mapper` are fulfilled, or rejects if any of the promises reject. The fulfilled value is an `Array` of the fulfilled values returned from `mapper` in order.

#### count

Type: `number`

Number of times to call `mapper`.

#### mapper(index)

Type: `Function`

Expected to return a `Promise` or value.

#### options

Type: `object`

##### concurrency

Type: `number`\
Default: `Infinity`\
Minimum: `1`

Number of concurrently pending promises returned by `mapper`.

##### stopOnError

Type: `boolean`\
Default: `true`

When set to `false`, instead of stopping when a promise rejects, it will wait for all the promises to settle and then reject with an [aggregated error](https://github.com/sindresorhus/aggregate-error) containing all the errors from the rejected promises.

## Related

- [p-forever](https://github.com/sindresorhus/p-forever) - Run promise-returning & async functions repeatedly until you end it
- [p-map](https://github.com/sindresorhus/p-map) - Map over promises concurrently
- [p-filter](https://github.com/sindresorhus/p-filter) - Filter promises concurrently
- [More…](https://github.com/sindresorhus/promise-fun)

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