# combine-async-iterators

> Combine Multiple Asynchronous Iterators in one (not a sequence)

Latest version **3.0.0** (published 2024-05-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install combine-async-iterators
pnpm add combine-async-iterators
yarn add combine-async-iterators
bun add combine-async-iterators
```

## Health

**Score 40/100 (D)** — status: abandoned.

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

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2024-05-08 |
| First published | 2019-07-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=20 |
| Dependencies | 0 |
| Unpacked size | 8.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 19 |
| Author | GENTILHOMME Thomas |
| Maintainers | fraxken |
| Keywords | async, asynchronous, iterator, iterators, iteration, iterable, combine, merge, build, construct, sequence |

## Links

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

## Alternatives

- [raw-loader](https://npm.io/package/raw-loader.md) — 4.3M weekly downloads
- [plop](https://npm.io/package/plop.md) — 1.4M weekly downloads
- [webpack-deadcode-plugin](https://npm.io/package/webpack-deadcode-plugin.md) — 80.3K weekly downloads
- [@storybook/preact-vite](https://npm.io/package/@storybook/preact-vite.md) — 54.2K weekly downloads
- [vite-plugin-transform](https://npm.io/package/vite-plugin-transform.md) — 2.4K weekly downloads

## Recent versions

- 3.0.0 (latest) — 2024-05-08
- 2.1.0 — 2023-09-10
- 2.0.1 — 2021-10-31
- 2.0.0 — 2020-10-08
- 1.1.2 — 2019-09-17
- 1.1.1 — 2019-07-23
- 1.1.0 — 2019-07-22
- 1.0.0 — 2019-07-22

## README

# Combine-async-iterators
![version](https://img.shields.io/badge/dynamic/json.svg?url=https://raw.githubusercontent.com/fraxken/combine-async-iterators/master/package.json&query=$.version&label=Version)
![MIT](https://img.shields.io/github/license/mashape/apistatus.svg)
![size](https://img.shields.io/bundlephobia/min/combine-async-iterators)
[![Known Vulnerabilities](https://snyk.io//test/github/fraxken/combine-async-iterators/badge.svg?targetFile=package.json)](https://snyk.io//test/github/fraxken/combine-async-iterators?targetFile=package.json)

Combine Multiple Asynchronous Iterators in one (not a sequence). It use **Promise.race** under the hood (the code idea is from [Targos](http://github.com/targos)).

> [!IMPORTANT]
> This package was mainly built to work with native Asynchronous Generators (Iterators).

## Requirements
- [Node.js](https://nodejs.org/en/) version 20 or higher

## Getting Started

This package is available in the Node Package Repository and can be easily installed with [npm](https://docs.npmjs.com/getting-started/what-is-npm) or [yarn](https://yarnpkg.com).

```bash
$ npm i combine-async-iterators
# or
$ yarn add combine-async-iterators
```

## Usage example
```js
const timers = require("node:times/promises");
const combineAsyncIterators = require("combine-async-iterators");

async function* getValues(id) {
    for (let count = 0; count < 5; count++) {
        await timers.setTimeout(Math.ceil(Math.random() * 1000));
        yield `${id}_${count}`;
    }
}

async function main() {
    const asyncIterator = combineAsyncIterators({}, getValues("first"), getValues("second"));
    for await (const value of asyncIterator) {
        console.log(value);
    }
}
main().catch(console.error);
```

**Since 2.0.0** it is also possible to recover errors through a callback. By default the method is stopped when an error is thrown (the `throwError` parameter allow to disable this behaviour).

```js
function errorCallback(err) {
    console.error("got you:", err);
}

const iteratorOptions = { errorCallback, throwError: false };
const asyncIterator = combineAsyncIterators(
  iteratorOptions,
  getValues("first"),
  getValues("second")
);
for await (const value of asyncIterator) {
    console.log(value);
}
```

## API

```ts
declare function combineAsyncIterators(
    ...iterators: AsyncIterableIterator<any>[]
): AsyncIterableIterator<any>;

declare namespace combineAsyncIterators {
    interface CombineOptions {
        throwError?: boolean;
        errorCallback?: (err: Error, index: number) => any;
    }
}

declare function combineAsyncIterators(
    options: combineAsyncIterators.CombineOptions,
    ...iterators: AsyncIterableIterator<any>[]
): AsyncIterableIterator<any>;

export = combineAsyncIterators;
```

## Contributors ✨

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-3-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
  <tbody>
    <tr>
      <td align="center" valign="top" width="14.28%"><a href="https://github.com/fraxken"><img src="https://avatars.githubusercontent.com/u/4438263?v=4?s=100" width="100px;" alt="Thomas.G"/><br /><sub><b>Thomas.G</b></sub></a><br /><a href="https://github.com/fraxken/combine-async-iterators/commits?author=fraxken" title="Code">💻</a> <a href="https://github.com/fraxken/combine-async-iterators/issues?q=author%3Afraxken" title="Bug reports">🐛</a> <a href="#security-fraxken" title="Security">🛡️</a></td>
      <td align="center" valign="top" width="14.28%"><a href="https://github.com/Farenheith"><img src="https://avatars.githubusercontent.com/u/5713887?v=4?s=100" width="100px;" alt="Thiago Oliveira Santos"/><br /><sub><b>Thiago Oliveira Santos</b></sub></a><br /><a href="https://github.com/fraxken/combine-async-iterators/commits?author=Farenheith" title="Code">💻</a></td>
      <td align="center" valign="top" width="14.28%"><a href="https://leozhang.me"><img src="https://avatars.githubusercontent.com/u/2092654?v=4?s=100" width="100px;" alt="Leo Zhang"/><br /><sub><b>Leo Zhang</b></sub></a><br /><a href="https://github.com/fraxken/combine-async-iterators/issues?q=author%3Aelldritch" title="Bug reports">🐛</a></td>
    </tr>
  </tbody>
</table>

<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->

<!-- ALL-CONTRIBUTORS-LIST:END -->

## Licence
MIT

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