Promises
- Definition : Helps you run functions asynchronously, and use their return values (or exceptions) but only once when executed.
- Not Lazy
- Not cancellable. The two possible decisions are
- Reject
- Resolve
- Cannot be retried(Promises should have access to the original function that returned the promise in order to have a retry capability, which is a bad practice)
Observables
- Definition : Helps you run functions asynchronously, and use their return values in a continous sequence(multiple times) when executed.
- By default, it is Lazy as it emits values when time progresses. It means until it is subscribed, it doesn't execute the function.
- Has a lot of operator which simplifies coding effort.
- One operator retry can be used to retry when ever needed, also if we need to retry the observable based on some conditions retryWhen can be used.Note: A list of operators along with their interactive diagrams is available here at RxMarbles.com
No comments:
Post a Comment