- Mastering Reactive JavaScript
- Erich de Souza Oliveira
- 97字
- 2021-07-09 20:33:07
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).
推薦閱讀
- Linux網(wǎng)絡(luò)管理與配置(第2版)
- Mastering ElasticSearch
- Learning OpenDaylight
- Linux從零開始學(xué)(視頻教學(xué)版)
- Mastering Distributed Tracing
- Ubuntu Linux操作系統(tǒng)
- Installing and Configuring Windows 10:70-698 Exam Guide
- 計算機(jī)系統(tǒng)開發(fā)與優(yōu)化實(shí)戰(zhàn)
- Python基礎(chǔ)教程(第3版)
- Windows Server 2019 Administration Fundamentals
- Linux使用和管理指南:從云原生到可觀測性
- Ceph分布式存儲實(shí)戰(zhàn)
- INSTANT Migration from Windows Server 2008 and 2008 R2 to 2012 How-to
- Azure Resource Manager Templates Quick Start Guide
- Mastering Sass