Struggling to understand why my requests aren't executing concurrently with the following code. As a newcomer to RxJS and observables, I would greatly appreciate any guidance on improving this snippet below. Essentially, I am fetching data from a REST API backend. Subsequently, for every element in the array of data, I'm calling a different endpoint using the 'forkJoin' operator. Despite sending all requests at once, they appear to execute sequentially rather than concurrently.
this.sites$.subscribe(data => {
var obs: Observable<any>[] = [];
for (var _i = 0; _i < data.length; _i++) {
this.siteCaptureMap[data[_i].id] = new CaptureData();
this.siteCaptureMap[data[_i].id].id = _i;
obs.push(this.sitesService.getCaptureData(data[_i].nameOrNumber, data[_i].owner.name));
}
forkJoin(obs).subscribe(results => {
for (var _i = 0; _i < results.length; _i++) {
this.siteCaptureMap[data[_i].id].count = results[_i].length;
}
});
this.dataSource.data = data;
this.dataSource.filteredData = data;
});
Your assistance is highly valued. If further clarification or additional code snippets are needed, please do not hesitate to reach out. Thank you for your help!