Reputation: 1319
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 tackling the same problem of an asynchronous stream of data. Is there a practical difference between the two, besides a matter of taste?
Upvotes: 6
Views: 1170
Reputation: 144
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.
Upvotes: 0
Reputation: 664764
Judging from the proposed API descriptions:
Observable
constructor does blur the linesObservables 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.
Upvotes: 14