Rxjs - Operators - ConcatMap

Signature

export declare function concatMap<T, I, R>(
project: (value: T, index: number) => ObservableInput<I>,
resultSelector?: (outerValue: T, innerValue: I, outerIndex: number, innerIndex: number) => R): any;

Parameters

因为是高阶流用的,所以project必须有

project是映射 怎么把外部流的每一个元素变成内部的子流方法
resultSelector 是把子流的元素再变化一次发给mergeMap后的操作

Note: concatMap is equivalent to mergeMap with concurrency parameter set to 1.

注意不止是共存流为1这样,如果第一个子流是无限不完成的,那就完蛋了,肯定和你预想的不一样

Sample

var letters = Rx.Observable.of('a', 'b', 'c');
var result = letters.concatMap(x =>
Rx.Observable.interval(1000).map(i => x + i).take(5),
(oV, iV, oI, iI) => {
// console.log("innerValue", iV);
return "inner"+iV;
}
);
result.subscribe(x => console.log(x));

解释