RxJS Crash Course – Convert Promise to Observable

0

If you work with asynchronous JavaScript you’re probably used to working with promises and we can convert a promise directly into an observable so here we’re just creating a promise with a timeout that resolves after one second. The idea here is to simulate an API call or some other asynchronous operation to convert this promise to an observable.


We just call observable from the promise and pass it the promise this is extremely useful. When you’re working with a JavaScript library that’s built on promises. And you can also convert the observable back to a promise by calling to promise on it.
So when we subscribe to this observable we get a one-second delay and then it prints resolved on the page.

Demo

Next article:

0