I need to send multiple HTTP PUT request to server sequentially (after the next request is only started after completing the previous request, the number of request is not fixed). If I use the below source code, all request will be sent
`listURL.forEach(url => {
const req = new HttpRequest('PUT', url, formData, { reportProgress: true});
httpClient.request(req).subscribe(event=>{});
});`
Is there anyway to execute the requests sequentially?
If you are not familiar with rxjs, perhaps you can try the following?
let requests = listURL.map(url => new HttpRequest('PUT', url, formData, { reportProgress: true});
function do_seq(i) {
httpClient.request(requests[i]).subscribe(event => {
if (i < requests.length - 1) do_seq(i + 1);
});
}
do_seq(0);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments