【发布时间】:2018-09-08 07:17:11
【问题描述】:
我使用的是 RxJS v6,但答案也适用于 RxJS v5。
我想这样做,如果我说 8 个值,我一次只会有 4 个被主动处理。
我现在的代码发送 4 个项目,然后等到所有 4 个完成,然后发送接下来的 4 个。我希望它发送前 4 个,然后当一个 observable 完成时,另一个进来待处理。
from([1, 2, 3, 4, 5, 6, 7, 8])
.pipe(
bufferCount(4),
concatMap(values => (
from(values)
.pipe(
mergeMap(value => (
timer(1000) // Async stuff would happen here
.pipe(
mapTo(value),
)
)),
)
)),
)
.subscribe(console.log)
【问题讨论】: