# many-promises

> Tool for managing sequential, parallel and a mix of those calculations using Promises in Javascript

Latest version **0.2.0** (published 2020-11-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install many-promises
pnpm add many-promises
yarn add many-promises
bun add many-promises
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2020-11-17 |
| First published | 2020-10-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | grumd |
| Maintainers | grumd |
| Keywords | promise, promises, mass, multiple, parallel, sequential, scheduler, simultaneous, jobs, array |

## Links

- npm: https://www.npmjs.com/package/many-promises
- Repository: https://github.com/grumd/many-promises
- Homepage: https://github.com/grumd/many-promises#readme
- Issues: https://github.com/grumd/many-promises/issues
- npm.io page: https://npm.io/package/many-promises

## Alternatives

- [cron](https://npm.io/package/cron.md) — 4.9M weekly downloads
- [@vercel/queue](https://npm.io/package/@vercel/queue.md) — 731.6K weekly downloads
- [create-sonicjs](https://npm.io/package/create-sonicjs.md) — 1.6K weekly downloads
- [@exellix/jobs-api](https://npm.io/package/@exellix/jobs-api.md) — 941 weekly downloads
- [@forwardimpact/libskill](https://npm.io/package/@forwardimpact/libskill.md) — 575 weekly downloads

## Recent versions

- 0.2.0 (latest) — 2020-11-17
- 0.1.2 — 2020-10-07
- 0.1.1 — 2020-10-06
- 0.1.0 — 2020-10-06

## README

# many-promises
[![npm version](https://img.shields.io/npm/v/many-promises.svg)](https://www.npmjs.com/package/many-promises) [![](https://travis-ci.org/grumd/many-promises.svg?branch=main)](https://travis-ci.org/github/grumd/many-promises) [![](https://img.shields.io/codecov/c/github/grumd/many-promises)](https://codecov.io/gh/grumd/many-promises)

**many-promises** allows sequential or parallel promise evaluation, including limiting number of promises that can be in progress at the same time. Includes Typescript typings, but can be used in Javascript projects as well.

## Installation

```
npm install many-promises
```

## Example

```js
import execute from 'many-promises';

const items = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

const job = (item) => Promise.resolve(item * 2);

const results = await execute({ items, job });
// Will call `job` for every `item` in `items` and await until all promises are resolved.
// results - [2, 4, 6, 8, 10, 12, 14, 16, 18, 20];
```

```js
// All promises in parallel:
const results = await execute({ items, job });
// All promises sequentially:
const results = await execute({ items, job, concurrentLimit: 1 });
// Maximum 3 jobs at the same time, but each job has a minimum 200ms duration:
const results = await execute({ items, job, concurrentLimit: 3, minJobTime: 200 });
```

## Reference

#### `execute(options: ExecuteOptions)`

```ts
type ExecuteOptions<ItemType, ResultType> = {
  items: ItemType[];
  job: (item: ItemType) => Promise<ResultType> | ResultType;
  concurrentLimit?: number | undefined | null;
  minJobTime?: number | undefined | null;
};
```

*Note:* Types ItemType and ResultType are usually inferred and you don't need to specify them explicitly.

##### `items`
Array of items of any type.

##### `job`
A function with one argument - which is an item from the `items` array.

##### `concurrentLimit` (optional)
Maximum number of Promises that can be in progress at the same time.
Default - `undefined`

##### `minJobTime` (optional)
Minimum time of execution for one job. If a job finishes earlier, next job will wait for this timeout to end before starting.
Default - `undefined`

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