我有以下代码尝试并行处理一组端点:
callApiEndpoint(endpoint: string): Observable<any> {
return this.httpClient
.get<any>(endpoint)
.pipe(
tap(
data =>
console.log(`calling ${endpoint} returned ${JSON.stringify(data)}`),
catchError(ApiCallerComponent.handleError)
)
);
}
getEndpointsToProcess(): string[] {
const result = [];
this.idsToProcess.forEach(element => {
result.push(this.getEndpoint(element));
});
return result;
}
processRequests() {
const endpoints = this.getEndpointsToProcess();
forkJoin(endpoints.map(uri => <Observable<any>>this.callApiEndpoint(uri)))
.pipe(concatAll())
.subscribe(val => console.log(val));
}
如何控制对API服务器的并行请求的程度?此外,无论结果如何,我怎么能说所有请求都已完成?