- 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運(yùn)維實(shí)戰(zhàn):CentOS7.6操作系統(tǒng)從入門(mén)到精通
- 從零開(kāi)始寫(xiě)Linux內(nèi)核:一書(shū)學(xué)透核心原理與實(shí)現(xiàn)
- 精通Linux內(nèi)核開(kāi)發(fā)
- 精解Windows8
- 高性能Linux服務(wù)器構(gòu)建實(shí)戰(zhàn):系統(tǒng)安全、故障排查、自動(dòng)化運(yùn)維與集群架構(gòu)
- Java EE 8 Design Patterns and Best Practices
- Ceph分布式存儲(chǔ)實(shí)戰(zhàn)
- Learning Magento 2 Administration
- 計(jì)算機(jī)系統(tǒng):基于x86+Linux平臺(tái)
- INSTANT Galleria Howto
- Cassandra 3.x High Availability(Second Edition)
- 從零開(kāi)始學(xué)安裝與重裝系統(tǒng)
- 鴻蒙HarmonyOS應(yīng)用開(kāi)發(fā)入門(mén)
- 電腦辦公(Windows 7 + Office 2013)入門(mén)與提高
- Drupal 7 Mobile Web Development Beginner’s Guide