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.
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. 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
There are also powerful operators like retry(), or replay(), … that are often quite handy.
- 1Bitbucket and Visual Studio
- 1How to dump and restore database in MongoDB
- 1How to compress and extract files/folders using the tar command on Ubuntu
- 5What is "marquee" tag and how I can use it in HTML?
- 1Generating a series of colors between two colors
- 1How To Create a New User and Grant Permissions in MySQL
- 1What is the difference between setTimeout and setInterval?
- 3What's the difference between using “let” and “var”?
- 1Abstract and Virtual Methods
- 1What is PATH, and when to use it in C++
- 1How to make my footer cover 100% height and width of the page from top?