4 ms·
Certainly there are overlaps in what you accomplish with both technologies, and the push/pull analogy isn't necessarily the best analogy to explain the distinct
by WorldMaker 9y ago
Certainly 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.