简体   繁体   English

RxJS forkJoin会按顺序返回结果吗?

[英]Will RxJS forkJoin return results in order?

RxJS provides a function called forkJoin . RxJS提供了一个名为forkJoin的函数。 It allows you to input multiple Observables and wait for all of them to finish. 它允许您输入多个Observables并等待所有Observables完成。 I am wondering if the resulting array will contain the results in the same order as the order of the input observables. 我想知道结果数组是否将包含与输入observable的顺序相同的顺序的结果。 If it wil not, which one of the operators does maintain the same order? 如果没有,哪一个运营商确实维持相同的订单? I've been looking into the docs and was not able to find the answer. 我一直在研究文档而无法找到答案。

It will return results in the same order. 它将以相同的顺序返回结果。 As is described in these official docs . 正如这些官方文档中所描述的那样。

Good to mention that it will emit only latest values of the streams: 很高兴提到它只会发出流的最新值:

var source = Rx.Observable.forkJoin(
  Rx.Observable.of(1,2,3),
  Rx.Observable.of(4)
);

source.subscribe(x => console.log("Result", x));

// LOG: Result [3,4]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM