Difference between Promise and Observable?
The both are used for handling asynchronous operations.
Key Difference - Promise emits a single value while Observable emits multiple values.
Suppose, while handling a HTTP request, Promise can manage a single response for the same request, but what if there are multiple responses to the same request, then we have to use Observable.
Becasue, Observable can handle multiple responses for the same request.
Note - Observable can be converted into Promise using toPromise() method
Observables are a part of the RXJS library.
|1.||Emit multiple values over a period of time.||Emit a single value at a time.|
|2.||It's lazy: only executed when we subscribe using subscribe() method.||It's not lazy: execute immediately after creation.|
|3.||Are cancellable using the unsubscribe() method||Are not cancellable.|