Observables compared with Functions

Screenshot (7665).png

  • 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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s