Knowledge Transfer

Tuesday, October 17, 2017

Promise vs Observable in Angular



https://stackoverflow.com/questions/37364973/angular-promise-vs-observable?rq=1

Both Promises and Observables will help us work with the asynchronous functionalities in JavaScript. They are very similar in most cases, however, there are some differences between the two, promises are values that will resolve in asynchronous way like http calls. On the other hand, observables deal with sequence of asynchronous events. The main differences are as below:
promise:
  • having one pipe line
  • usually only use with async data return
  • not easy to cancel
observable:
  • are cancellable
  • are retriable by nature such as retry and retryWhen
  • stream data in multiple pipe lines
  • having array-like operations like map, filter etc
  • can be created from other sources like events
  • they are function, which could be subscribed later on
Also, I've created the graphical image for you below to show the differences visually:
Promises and Observables image
Thanks,
Bhaskar

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]



<< Home