O'Reilly logo

Mastering Reactive JavaScript by Erich de Souza Oliveira

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Observables from promises (fromPromise)

You can also create EventStreams from ES6 promises or jQuery AJAX. These streams will contain only a single value (or an error in case of failure), and finish. We will need a promise to test this method:

var promiseObject = Promise.resolve(10); 

Here, we are creating a successful promise that will return the value 10. To transform this promise into an EventStream, we use the following code:

Bacon    .fromPromise(promiseObject); 
Keep in mind you will need Node.js version 4 or above, or a modern browser to test this code (old browsers don't have promises implemented).

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required