Angular : Difference in Promises v/s Observables
What are the differences between promises and observables in Angular 2x+?
Following is the list of differences between promises and observables in Angular:
Promises | Observables |
---|---|
Promises can deal with a single asynchronous event at a time. | The observables can handle a sequence of asynchronous events over a period of time. |
Promises are always asynchronous. | Observables are both synchronous as well as asynchronous. |
Promises generally provide only a single value. | Observables can emit multiple values. |
Promises are not lazy. They can execute immediately after creation. | Observables are very lazy. They can't be executed until you subscribe to them using the subscribe() method. |
Promises are not cancellable. | Observables have subscriptions that can be canceled using the unsubscribe() method. After that, they stop the listener from receiving further values. |
Promises don't provide any operations. | Observables provide the map for forEach, filter, reduce, retry, and retryWhen operators. |
Promises push errors to the child promises. | Observables deliver errors to subscribers. |
Comments
Post a Comment