Observable vs Promise in Angular
If you just started working with Angular recently and if you worked with Asynchronous Operations you might have come across this common confusion, what is the difference between an Observable and a Promise?
Firstly, what are Asynchronous and Synchronous Operations?
In basic terms, when you execute Synchronous operations, you wait for it to finish before moving on to another task.
Likewise, when you execute Asynchronous operations, you are able to move to another task before it finishes.
If you are still confused, Synchronous operations work in a step by step order once the previous task is completed then only it moves to the next one but in Asynchronous operations it doesn’t wait for the previous task to complete instead it lets the previous task to takes it time to complete while completing the other tasks.
What are Promises ?
Promise is an object that may produce a single value some time in the future, either a resolved value or a reason that it’s not resolved(e.g. may be due to a network error) or in a pending state.