【发布时间】:2020-08-11 05:17:15
【问题描述】:
试图找出我是否可以在递归 forkJoin 中等待所有 http 调用。如何等待 forkJoin 中的所有 http 调用并接收最终结果?
目前我有类似以下的内容
public myMethod(urls: string[]) {
...
return forkJoin(observables)
.pipe(map(() => {
if (json.urls !== 0) {
return this.myMethod(json.urls);
}
}), catchError((err) => {
console.log(err);
return of(null);
})
);
}
And then I subscribe ...
public mainMehtod(){
return this.myMethod([json]).pipe(map(() => {
...some stuff here. But I need here the final result from the finished recursion
}));
编辑
我找到的解决方案是,在递归中收集所有可观察对象,然后调用 forkjoin。
【问题讨论】:
-
什么是递归?
-
expand可用于递归调用,但需要有关此函数的更多详细信息才能为您的特定情况提供工作示例
标签: angular typescript http async-await rxjs