- An observable can be understood as a more generic form of a function.
- function.call() is equivalent to observable.subscribe() coz the former executes the function while the latter executes the observable.
- Now, though the function can only return 1 value to the caller, the observable can return multiple values to the subscriber over time.
- A more accurate comparison would be that of a Generator function with an Observable, coz a generator function actually is capable of returning multiple values over time.
- Coz Generators allow 2 way message exchange b/w the caller and the callee, you’d use it in scenarios that require that, but observables are helpful in scenarios of pub sub, where you need to publish data over time to subscribers.
- Moreover observables (specially the rxjs implementation) follow a stricter contract than generators in that a observable can send only next value, error or complete.
- Observables are like a pub sub library for the Web.