# promise-map-limit

> Map an array n items at a time with promises

Latest version **1.0.0** (published 2016-11-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install promise-map-limit
pnpm add promise-map-limit
yarn add promise-map-limit
bun add promise-map-limit
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2016-11-02 |
| First published | 2016-11-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/promise-map-limit) |
| Module format | CommonJS |
| Node | >=4 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | David Brockman Smoliansky @dbrckmn |
| Maintainers | dbrockman |
| Keywords | promise, limit, limited, concurrency, throttle, rate, batch, ratelimit, queue, async, await, promises |

## Links

- npm: https://www.npmjs.com/package/promise-map-limit
- Repository: https://github.com/dbrockman/promise-map-limit
- Homepage: https://github.com/dbrockman/promise-map-limit#readme
- Issues: https://github.com/dbrockman/promise-map-limit/issues
- npm.io page: https://npm.io/package/promise-map-limit

## Alternatives

- [promise-throttle](https://npm.io/package/promise-throttle.md) — 44.2K weekly downloads
- [@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

## Recent versions

- 1.0.0 (latest) — 2016-11-02

## README

# promise-map-limit

Map an array n items at a time with promises


## API

### `mapLimit(iterable, limit, iteratee)`

#### Parameters:

- `iterable` The collection to iterate over. The iterator interface will be used if it is implemented. If the collection does not implement the iterator interface then `Object.keys()` is used and values are iterated in the order of the keys.
- `limit` The concurrency limit. The maximum number of async operations at a time.
- `iteratee` The function that will be called with each value in `iterable`. It can return a `Promise` or a plain value if no async operation is needed. If the `iteratee` function throws then `mapLimit` aborts and rejects with the error.

#### Returns:

`mapLimit` returns a `Promise<Array>` that resolves with the transformed values from `iterable`.
If `iteratee` throws or returns a rejected promise then `mapLimit` will abort and return a rejected promise with the same error.

## Example

```js
const mapLimit = require('promise-map-limit');

// This will work on max two items in the array at a time
// When all items are processed it will resolve with the resulting array in the same order.
mapLimit([1, 2, 3, 4], 2, n => Promise.resolve(n * 2)).then(array => {
  // array == [2, 4, 6, 8]
});

// The iterator function can return the result synchronous
mapLimit([1, 2, 3, 4], 2, n => n * 2).then(array => {
  // array == [2, 4, 6, 8]
});

// Any value that implements the iterator interface can be used, such as Array, String, Map, Set
mapLimit('abc', 2, str => str.toUpperCase()).then(array => {
  // array == ['A', 'B', 'C']
});

// Any value that implements the iterator interface can be used, such as Array, String, Map, Set
mapLimit('abc', 2, str => str.toUpperCase()).then(array => {
  // array == ['A', 'B', 'C']
});

// Iterator object also implements the iterator interface
const arr = ['a', 'b', 'c'];
const iterator = a.entries();
mapLimit(iterator, 2, entry => entry).then(array => {
  // array == [
  //   [0, 'a'],
  //   [1, 'b'],
  //   [2, 'c']
  // ]
});

// If the iterator is omitted, each function in the array is executed
// This will run max two functions at a time
mapLimit([
  () => Promise.resolve(1),
  () => Promise.resolve(2),
  () => 3, // can be sync
  () => Promise.resolve(4),
], 2).then(array => {
  // array == [1, 2, 3, 4]
});
```

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