3 ms·
Hmm I don't follow. Wouldn't a generator function producing async iterators be "push"? Without any Rx involved? I mean, ever since JS got generators, it has su
by skrebbel 9y ago
Hmm I don't follow. Wouldn't a generator function producing async iterators be "push"? Without any Rx involved?
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.
- WorldMaker 9y agoCertainly there are overlaps in what you accomplish with both technologies, and the push/pull analogy isn't necessarily the best analogy to explain the distinction, but it's the best one I currently have. 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.