Promises vs Observables - Angular Tutorial

preview_player
Показать описание
In this video I have explained the key differences between promise and observables.
Promises and Observables are both tools used for handling asynchronous operations in JavaScript, but they have some key differences:

Promise -
Single Value: A Promise represents a single value that may be available now, in the future, or never. Once it is resolved or rejected, it cannot be changed.
Eager Execution: Promises start executing immediately when created.
Not Lazy: Promises are not lazy; they do not wait for subscription or call to start.
Not Cancelable: Once a Promise starts, it cannot be canceled.
Simple Error Handling: Promises have straightforward error handling using .then() for success and .catch() for errors.
Chaining: Promises support chaining to handle a sequence of asynchronous operations.

--------------------------------------------------------------------------------------------------------------------
Observable-
Multiple Values: An Observable can emit multiple values over time, which makes it suitable for scenarios like events or streams of data.
Lazy Execution: Observables are lazy; they don’t start emitting values until a subscription is made.
Cancelable: Observables can be canceled by unsubscribing, which stops the emission of values.
Complex Error Handling: Observables provide more complex error handling mechanisms and can retry or handle errors in sophisticated ways.
Operators: Observables come with a variety of operators (map, filter, reduce, etc.) that allow for powerful manipulation of the emitted values.
Streams: Observables are often used to handle streams of data, making them suitable for real-time applications.
In summary, Promises are great for handling a single asynchronous value, while Observables are more powerful for dealing with multiple values or streams of asynchronous data.
Рекомендации по теме
Комментарии
Автор

Sir make an video of how to scroll top bottom in angular

informer