- 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操作系統基礎
- 高性能Linux服務器構建實戰:運維監控、性能調優與集群應用
- 構建可擴展分布式系統:方法與實踐
- Linux集群和自動化運維
- 異質結原理與器件
- 混沌工程:復雜系統韌性實現之道
- 完美應用RHEL 8
- Learning Magento 2 Administration
- 一學就會:Windows Vista應用完全自學手冊
- Delphi Programming Projects
- INSTANT Migration from Windows Server 2008 and 2008 R2 to 2012 How-to
- iOS 10 開發指南
- Windows網絡編程(第2版)
- Less Web Development Essentials