# each-async

> Async concurrent iterator (async forEach)

Latest version **2.0.0** (published 2021-05-03) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install each-async
pnpm add each-async
yarn add each-async
bun add each-async
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2021-05-03 |
| First published | 2013-12-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.10.0 |
| Dependencies | 2 |
| Unpacked size | 4.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 112 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | each, async, asynchronous, iteration, iterate, loop, foreach, parallel, concurrent, array, flow, control flow |

## Links

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

## Dependencies (2)

- [onetime](https://npm.io/package/onetime.md) ^1.0.0
- [set-immediate-shim](https://npm.io/package/set-immediate-shim.md) ^1.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

- 2.0.0 (latest) — 2021-05-03
- 1.1.1 — 2014-12-29
- 1.1.0 — 2014-09-20
- 1.0.0 — 2014-08-13
- 0.1.3 — 2014-04-29
- 0.1.2 — 2014-02-07
- 0.1.1 — 2013-12-07
- 0.1.0 — 2013-12-01

## README

# each-async

> Async concurrent iterator (async forEach)

Like [async.each()](https://github.com/caolan/async#eacharr-iterator-callback), but tiny.

I often use `async.each()` for doing async operations when iterating, but I almost never use the other gadzillion methods in `async`.

Async iteration is one of the most used async control flow patterns.

**I would strongly recommend using promises instead. You could then use the built-in [`Promise.all()`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise/all), or [`p-map`](https://github.com/sindresorhus/p-map) if you need concurrency control.**


## Install

```
$ npm install --save each-async
```


## Usage

```js
const eachAsync = require('each-async');

eachAsync(['foo','bar','baz'], (item, index, done) => {
	console.log(item, index);
	done();
}, error => {
	console.log('finished');
});
//=> 'foo 0'
//=> 'bar 1'
//=> 'baz 2'
//=> 'finished'
```


## API

### eachAsync(input, callback, [finishedCallback])

#### input

Type: `Array`

Array you want to iterate.

#### callback(item, index, done)

Type: `Function`

Called for each item in the array with the following arguments:

- `item`: the current item in the array
- `index`: the current index
- `done([error])`: call this when you're done with an optional error. Supplying anything other than `undefined`/`null` will stop the iteration.

Note that order is not guaranteed since each item is handled concurrently.

#### finishedCallback(error)

Type: `Function`

Called when the iteration is finished or on the first error. First argument is the error passed from `done()` in the `callback`.


## License

MIT © [Sindre Sorhus](https://sindresorhus.com)

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