But I bet I'm missing something important. Rx is pretty huge and it looks like this feature isn't really. Does anyone know more, from the trenches? What are the downsides? Does Babel compile it well? Are all important use cases covered?
But I bet I'm missing something important. Rx is pretty huge and it looks like this feature isn't really. Does anyone know more, from the trenches? What are the downsides? Does Babel compile it well? Are all important use cases covered?
They work great together, using each's strengths to specific needs in an application.
Additionally, a lot of the weight of Rx is its large set of "higher order functions" beyond the basics of map/filter/reduce. Similar higher order functions are possible for async iterators. One such library for that is Ix, maintained by some overlap with the Rx team, and maintaining some consistency in operator names and APIs.
I've been using Async Iterables fairly heavily lately in an application in combination with Rx-like Observables (using the xstream library, rather than Rx) and Ix operators. I've been letting Typescript do all the downlevel compilation, and have been pretty happy with it in the use cases where I've been using it.
I mean, ever since JS got generators, it has support for unlimited length iterables. Isn't an unlimited iterable of promises precisely what you describe as a push stream?
I didn't dive deep, but I do believe I was able to cook up a generator function that produces an async iterable of mouse events. It was able to `for await` it and console log the event data.
Async Iterators/Generators are seen as "pull" because your "main thread" has to actively consume it (you `for await` results), whereas with Rx Stream/Observables your "main thread" passively subscribes to updates.
It probably still seems like a semantic distinction at that, especially as you can relatively easily convert between them. However, a lot of the big differences come down to how each technology deals with A) pressure (lots of items/events), and B) scheduling "intermediate" work (iterables do more work on the "main thread"; streams/observables are better at/have more tools for chunking work on a scheduler/thread pool outside of the "main thread").
Which is also why JS isn't exactly the best language to discuss the differences between async iterators and streams/iterables, because a lot of those biggest differences/distinctions aren't very important in mostly-single-threaded browser JS, which is its most common problem domain.