Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Promises vs Observable

Promise is eager, once they are initialized they Trigger the underlying actions and returns the result
Observable is lazy, they don’t trigger until it has a subscriber.

Promises returns only one value
Observable can return multiple valuesovertime to its subscribers

Promise cannot be canceled, once a promise action is triggered it will execute and return the result
Observable can be canceled, we can call unsubscribe to stop receiving responses from the observable

Promises can be converted to observables, the RxJs library provides a from operator which can convert a promise to an observable. We can use this to deal with some legacy code that is returning promises.

import { from } from 'rxjs';
const myObservable = from(myPromise)


This post first appeared on C# Guide, please read the originial post: here

Share the post

Promises vs Observable

×

Subscribe to C# Guide

Get updates delivered right to your inbox!

Thank you for your subscription

×