Deepak Verma
Differentiate between Observables and Promises.
By Deepak Verma in Angular on Jun 19 2018
  • Shivam Shukla
    Jun, 2018 27

    Promises:return a single value not cancellable more readable code with try/catch and async/await Observables:work with multiple values over time cancellable support map, filter, reduce and similar operators use Reactive Extensions (RxJS) an array whose items arrive asynchronously over time

    • 5
  • Appsierra Solutions
    Jun, 2018 26

    hello deepak, A Promise handles a single event when an async operation completes or fails. Note: There are Promise libraries out there that support cancellation, but ES6 Promise doesn’t so far. An Observable is like a Stream (in many languages) and allows to pass zero or more events where the callback is called for each event.

    • 1
  • Bhairab Dutt
    Jun, 2018 26

    Hi Deepak,Both we are using for getting the response . The main difference is :1- A Promise handles a single event when an async operation completes or fails while An Observable is like a Stream and allows to pass zero or more events where the callback is called for each event.2- Observable is preferred over Promise because observable is cancelable while promise can not .3- Observable support map, filter, reduce and similar operators .4- With the Observable we are using Rxjs which is the great thing in angular because Rxjs is a library for reactive programming using observables that makes it easier to compose asynchronous or callback-based code.Hope Its help you .

    • 1
  • Ashish Ranjan
    Jun, 2018 26

    Promise :A Promise handles a single event when an async operation completes or fails.Observable:An Observable is like a Stream of data that allows to pass zero or more events where the callback is called for each event.Often Observable is preferred over Promise because it provides the features of Promise and more. With Observable it doesn't matter if you want to handle one or multiple events. You can utilize the same API in each case.Observable also has the advantage over Promise to be cancelable. If the result of an HTTP request to a server or some other expensive async operation isn't needed anymore, the Subscription of an Observable allows to cancel the subscription, while a Promise will eventually call the success or failed callback even when you don't need the notification or the result it provides anymore.Observable provides operators like map, forEach, reduce, ... similar to an array

    • 1
  • Abhijit Sahoo
    Jul, 2018 4

    An Observable is like a Stream (in many languages) and allows to pass zero or more events where the callback is called for each event. Often Observable is preferred over Promise because it provides the features of Promise and more. With Observable it doesn't matter if you want to handle 0, 1, or multiple events.

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS