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
的异步执行?
答案 0 :(得分:2)
您应该使用concatMap
而不是map
并从其回调中返回Observable:
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*/ });