user3909296 user3909296 - 4 months ago 52
TypeScript Question

How can I make hundreds of async calls in Angular2 and update view accordingly?

I want to perform hundreds of async HTTP Post requests (creating a new resource) in Angular 2 in a simple for loop and update an internal counter that is incremented by one as soon as one HTTP Post request successfully returns. I use rxjs Observables for handling the response from the backend.

However, if I do that I can get into race conditions if two responses arrive simultaneously and are about to update the internal counter at the same time. What is a proper solution in Angular2 and TypeScript for that?


JS is single threaded (or more specifically runs in a single threaded event loop), I don't think you need to worry about 2 responses updating a variable at the same time.