Creating an observable from a promise

The promises are objects that hold the result of an asynchronous computation. They are becoming more common now. One of the cool things about promises is that you can compose them with other promises or synchronous values, giving you an extra layer of abstraction over asynchronous computations. We can wrap a promise into an observable. This provides us a lot more power to handle the result of our computation using the operators from RxJS.

To do this, we can use the fromPromise() built-in method. This method can turn any A+ Promise into an observable.

Promises/A+ is a specification of promises. All the famous promises libraries in JavaScript follow this pattern; it is the same pattern followed by the standard ...

Get Mastering Reactive JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.