如何做序列映射,以便每个映射都等待rxjs中的前一个映射? [英] How to do sequence maps so that each map waits for the previous in rxjs?
本文介绍了如何做序列映射,以便每个映射都等待rxjs中的前一个映射?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
const source = Rx.Observable.from([1, 2, 3, 4, 5]);
const example = source.map(val => { /* asynchronous logic here*/ })
.map(val => { /* asynchronous logic here*/ });
.map(val => { /* asynchronous logic here*/ });
如何使每个map
等待上一个map
的异步执行?
How to make so that each map
waits for the asynchrounous execution of the previous map
?
推荐答案
您应使用concatMap
而不是map
并从其回调中返回Observable:
You should use concatMap
instead of map
and return Observable from its callback:
const source = Rx.Observable.from([1, 2, 3, 4, 5]);
const example = source
.concatMap(val => { /* asynchronous logic here*/ })
.concatMap(val => { /* asynchronous logic here*/ })
.concatMap(val => { /* asynchronous logic here*/ });
这篇关于如何做序列映射,以便每个映射都等待rxjs中的前一个映射?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文