fast-merge-async-iterators: merge AsyncIterables with all corner cases covered
The idea is to build a ES2018+ compatible module which really covers all the features of AsyncIterator, AsyncIterable, AsyncGenerator and doesn't throw the baby out with the bathwater.
...for await mergegen1, gen2, gen3...for await merge"iters-close-wait", gen1, gen2, gen3
- Interleaves the values yielded by the inner AsyncIterables as soon as they arrive.
- Supports exceptions propagation down the stack: if an inner iterator throws, then all other iterators will be closed (with or without waiting), and then the exception will be delivered to the caller.
- Works fast and with no memory leak in Promise.race().
- Closes merging iterators correctly once the caller stops iterating the merged
.return()for them which effectively triggers all their
A yielded 0 B yielded 0 Received from A: 0 Received from B: 0 A yielded 1 Received from A: 1 A yielded 2 Closing A (doing some cleanup) B yielded 1 Closing B (doing some cleanup) Finishing
The alternative libraries mentioned below have one or more flaws. Mostly it's about inability to close the inner iterators once the merged iterator is closed, having a memory leak when one iterator finishes early, and about having an overcomplicated/slow code.
Situation: There are 6 different libraries to merge AsyncIterables with different bugs and corner cases.
Cueball: 6?! Ridiculous! We need to develop one universal library that covers everyone's use cases.
(Soon) Situation: There are 7 different libraries to merge AsyncIterables.