1
I need to make an http request for each element of my product array.
I tried to do with for() but sometimes it doesn’t work, my browser stops working and it costs to close (I thought it could be because of the number of requests fired, but currently I’m testing with only two elements in the array and the browser keeps crashing).
I tried that way:
for(let i=0;i<this.produtosConfirmadosAnuncio.length;i++){
this.marketplaceService.anunciar(this.produtosConfirmadosAnuncio[i])
.pipe(
take(1)
)
.subscribe((res) => {
this.submited = false;
for (let c = 0; c < this.produtosConfirmadosAnuncio.length; c++) {
if (this.produtosConfirmadosAnuncio[c].id == this.produtosConfirmadosAnuncio[i].id) {
this.produtosConfirmadosAnuncio.splice(c, 1)
}
c--;
} //Remove the element when requisition return success
this.valorAtualProgress += this.quantidadeSomarProgress; //sum progress bar
if (this.valorAtualProgress == 100) { //close the progress bar when value is 100
this.toastrService.showToast(true, "Pronto!", res.mensagem);
}
}, (err) => {
this.loadingprogress = false
if (err.status == 401) {
this.authService.Logout();
}
})
}
Is there any other way I might be making multiple http requests?
There is a Pattern called Publisher Consumer that you can use as a reference to your problem.
– anderson macedo