Hi StackOverflow community members,
I am working on Angular 8. I have a question on how to breakdown my HTTP request, instead of sending 1000 requests in 1 go, I would like to have something like sending every 50 requests at 1 time only. I couldn't think of any way of achieving this. Below is my code snippets:
for (let i = 0; i < products.length; i++) {
this.myService.getProductInfoByCountryAndProductId(this.selectedCountries, this.product[i])
.subscribe(
(res) => { //get result },
(error) => { //throw error },
() => { //do something here });
}
The code above would triggers all the requests in 1 go, imagine if I have 1000 products in products
array, meaning it would loop 1000 times, and 1000 requests would sent to the server and caused performance issue. Is there any way to limit the client not to send all request in one go?
I've tried combineLatest
, the outcome isn't what I want. I wanted to try concatMap
but meaning it would send HTTP request 1 by 1 and going to take a long time to process all the products. Any suggestions or ideas?