What is the difference between observable and promises?

Member

by ashtyn , in category: Technology , 4 years ago

What is the difference between observable and promises?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by oda.tromp , 4 years ago

The differences between observable and promises are:

  • Observable is a more powerful way of handling HTTP asynchronous requests. Whereas, A promise handles a single event when an asynchronous operation completes or fails.
  • An observable is like a stream which allows passing zero or more events where the callback is called for each event. Whereas, A promise eventually calls the success or failed callback even when you don’t need the notification or the result it provides anymore.
  • Observable works with multiple values for a particular time. Whereas, Promises works with and even returns a single value at a time.
  • Observables can be canceled. Whereas, Promises cannot be canceled.
  • Observable supports map, filter, reduce and similar operators. Whereas, Promises have more readable codes with try/catch and async/await.
  • In observable, one operator ‘retry’ can be used to retry whenever needed. Whereas, Promises cannot be retried. A promise should have access to the original function that returned the promise in order to have a retry capability.

Related Threads:

How to cache an observable data in Angular 2 ?
What is difference Between PHP 5 and 7?
What is the difference between Serializable and parseable?
What is difference between stock and share?
What is difference between Oracle and SQL?
What are the difference between GUI and CLI?