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:

PromisesObservables
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

Popular posts from this blog

PUTTY - The server's host key is not cached in the registry cache

OIM-12c Installation - FMW - SOA - IDM

SAML & OAuth 2.0