Rxjs:Observable.combineLatest 与 Observable.forkJoin [英] Rxjs: Observable.combineLatest vs Observable.forkJoin
问题描述
我想知道 Observable.combineLatest
和 Observable.forkJoin
之间有什么区别?
I'm wondering what are the differences between Observable.combineLatest
and Observable.forkJoin
?
据我所知,唯一的区别是 forkJoin
期望 Observables 完成,而 combineLatest
返回最新值.
As far as I can see, the only difference is forkJoin
expects the Observables to be completed, while combineLatest
returns the latest values.
推荐答案
forkJoin
不仅要求完成所有输入的 observable,而且还返回一个 observable,它产生一个单一的值输入 observables 产生的最后一个值的数组.换句话说,它等待最后一个输入 observable 完成,然后产生一个值并完成.
Not only does forkJoin
require all input observables to be completed, but it also returns an observable that produces a single value that is an array of the last values produced by the input observables. In other words, it waits until the last input observable completes, and then produces a single value and completes.
相比之下,combineLatest
返回一个 Observable,一旦所有输入 observable 至少产生一个值,它就会在每次输入 observable 执行时产生一个新值.这意味着它可能具有无限值并且可能不完整.这也意味着输入 observable 不必在生成值之前完成.
In contrast, combineLatest
returns an Observable that produces a new value every time the input observables do, once all input observables have produced at least one value. This means it could have infinite values and may not complete. It also means that the input observables don't have to complete before producing a value.
这篇关于Rxjs:Observable.combineLatest 与 Observable.forkJoin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!