首页 > 解决方案 > forkJoin some observables with name observable function in result?

问题描述

Lets suppose there is array of Observable function:

A(): Observable<any>
B(): Observable<any>

Then using forkJoin I await response from both Observables:

let g = forkJoin([A(), B()]);

After subscription on g I can get results from both Observables.

Due this question, how to know from which Observable I have got result, I mean A(), or B().

Is it possible to get names or reference to these functions?

More detailed explanation:

I have unknown number of Observable functions. I need to wait them executions, to get response then enable button. So, also I need to handle response in each of them body, or in common body response in forkJoin

标签: angularrxjsobservableangular6angular2-observables

解决方案


新的 observable 将解析一个结果数组,这些结果的顺序与forkJoin

g.subscribe([a, b] => {
  console.log(a);
  console.log(b);
})

请参阅文档中的示例 5


推荐阅读