Skip to content Skip to sidebar Skip to footer

What Is The Difference Between Async Generators And Observables?

Async generators: An example case is a readable stream Observables: A fundamental protocol for processing asynchronous streams of data These both seem like different ways of tackli

Solution 1:

Judging from the proposed API descriptions:

  • observables can have multiple subscribers (broadcast), asynchronous iterators can only have a single reader (unicast)
  • observables push the events, while asynchronous iterators need to be polled
  • admittedly, the lazy nature of the Observable constructor does blur the lines

Observables are basically event emitters, while asynchronous iterators can be used to form a streaming flow. I also recommend the General Theory of Reactivity as a good read.


Solution 2:

I believe the answer could be found in their definition. A Generator function has the ability to stop and then continue later. An Observable can also stop and continue later but you need to subscribe to it first for it to begin.

First Difference - A generator executes when that function is called. An Observable technically only begins to execute or emit values when you subscribe to it.


Post a Comment for "What Is The Difference Between Async Generators And Observables?"