上QQ阅读APP看书,第一时间看更新
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).