Saturday, 14 December 2019

What are the differences between observables and promises in JavaScript?

Answer


Answer





So i've read that observables are looking to overtake promises in terms of usage in some of upcoming JavaScript MVC's:





What is the difference between observables and promises?



Updated: Apologies! removed my falsy statement.


Answer




What is the difference between observables and promises?





Simply put: A promise resolves to a single value asynchronously, an observable resolves to (or emits) multiple values asynchronously (over time).



Concrete examples:




  • Promise: Response from an Ajax call

  • Observable: Click events




More information can be found here: http://reactivex.io/intro.html




i've read that observables are looking to overtake promises




Unlikely. Observables might be the better solution to certain problems, but that doesn't make promises obsolete (if that's what you mean).


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print ...