Design Patterns · Senior · Question 12 of 75
How does an RxJS Observable differ from a Promise?
- ✓Correct answer: An Observable is a lazy, cancellable stream; a Promise is a single value
- 2An Observable is always synchronous, a Promise always asynchronous
- 3Observable is the old name of Promise from early JS versions
Explanation
A promise starts immediately, delivers one value and can't be cancelled. An Observable starts on subscription, can emit many values (events, WebSocket), is cancelled by unsubscribing and has operators (debounceTime, switchMap). It's an implementation of Observer + Iterator.