JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1223
  • Score
    100M100P100Q113855F
  • License MIT

merges async iterators

Package Exports

  • mergeiterator

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (mergeiterator) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

mergeIterator

Merges async iterators.

Using

This utility is for merging together async iterators.

Pass it a collection of iterables and it'll return an iterator, which will contain all values from those iterables. Those iterables and the collection of them can be arrays, calls to generators, or any other kind of iterable, synchronous or async, finite or infinite.

import merge from "mergeiterator"

async function DoIt() {
    for await (const v of merge([
        [1,2,3],
        (function *() { let i = 6; while (true) yield (i++) })(),
        (async function *() { yield await Promise.resolve(4); yield Promise.resolve(5) })(),
    ])) {
        console.log(v)
    }
}
// 1 6 2 7 4 3 8 5 9 10 11 ...

mergeIterator function guarantees, that if some value is yielded by some of iterables that mergeIterator is passed, then that value will be eventually yielded by mergeIterator. It also guarantees that the order of values within the same iterable is preserved.

Be aware, that mergeIterator will wait for any promise yielded by some iterable to be resolved before yielding its value and before asking that iterable for the rest of new values.

If some iterable throws an error, that error will be redirected to a caller and other iterables will be closed.

Contributing

Please contribute! All contributions are greatly appreciated no matter how small or large the contribution is. Whether it's a small grammar fix in the README, a huge bug fix, or just an issue report, you will be recognized as a 'Contributor' to this project.

Please, feel free to open an issue or email me to developer@vadzim.info if you have any question.