merge-async-iterators

0.2.1 • Public • Published

merge-async-iterators

A simple async iterators merger

Requires ES2018 Async Iteration

Install

npm i merge-async-iterators

Usage

API

merge([...iterators], opts)

  • iterators Array of async iterables

  • opts

    • yieldIterator[=false] Yields {iterator, value} (instead of value)

      Useful if you wanna know which iterator yielded the value

  • Returns A single merged async iterable

Example

const merge = require('merge-async-iterators');
 
const array = [1,2];
const iterable = (function*(){
  yield 3
  yield 4
})()
const asyncIterable = (async function*(){
  yield 5
  yield 6
})()
 
for await (const value of merge([array, iterable, asyncIterable])) {
  console.log(value)
}
1
2          // order isn't guaranteed
undefined  // finished iterators' returns will yield as well
3
4
undefined
5          // async wil almost always come after normal ones
6

Alternatives

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.2.1206latest

Version History

VersionDownloads (Last 7 Days)Published
0.2.1206
0.2.00
0.1.21
0.1.11
0.1.01

Package Sidebar

Install

npm i merge-async-iterators

Weekly Downloads

209

Version

0.2.1

License

none

Unpacked Size

5.46 kB

Total Files

4

Last publish

Collaborators

  • laggingreflex