In my app, I have a scenario where I need to fetch JSON data in a series of "category data" subscriptions inside a for loop. This data is then filtered based on the user's current location. The issue I'm facing is that my app doesn't wait for all the subscriptions to complete before proceeding. It only completes a few and then proceeds, leaving others running in the background.
I've attempted a brute force approach to this problem by predicting the number of categories that will be added to the filtered array. While this works, it's not a generic solution that can adapt to different situations.
Here's the relevant code snippet:
getMultipleCategoryData(categoryIds: string[]) {
// Code implementation goes here...
}
Additionally, here is the method responsible for fetching category data:
getCategoryData(categoryId): Observable<any> {
// Code implementation goes here...
}
Everything seems to be functioning properly except for the synchronization of the subscriptions' completion. I would greatly appreciate any guidance on how to accurately determine when all subscriptions have finished processing. Thank you for your assistance!