RubenVerborgh / AsyncIterator

An asynchronous iterator library for advanced object pipelines in JavaScript
https://rubenverborgh.github.io/AsyncIterator/docs/
Other
48 stars 7 forks source link

Feature request: merge multiple async iterators #11

Closed pietercolpaert closed 4 years ago

pietercolpaert commented 6 years ago

A function merge on an AsyncIterator would be a great tool to e.g., merge sort different iterators:

require('async-iterator').merge([iterators], function (a, b) { return a.departureTime < b.departureTime})

Which element is emitted next is based on a boolean condition.

RubenVerborgh commented 6 years ago

I think @rubensworks made a library that does this. Might be able to steal that code.

rubensworks commented 6 years ago

Yes, I made asynciterator-union, which takes the union of two streams, but it doesn't do sorting. It should not be too hard to extend it with a comparator-based iterator though.

(Note to self: we may need a new abstraction, where both RoundRobinUnionIterator and MergeSortUnionIterator extend from it)

RubenVerborgh commented 4 years ago

Now also available in this library itself: f405a7d201a1a82d5dd25bdb3c3209b89241f84f