this is my first time to develop a react/node js application.
The current hooks setup to call api is the line of code below.
The current setup is that application use Promises.all to call all promise that invoke axios.post and runs in parallel. The browser threads pool with default 5 concurrency level in chrome and starts other request if one of the 5 requests in the pool finished earlier.
But there is a change in requirements that before invoking axios.post, the numbers must be arranged in ascending and be called in sequential order.
Original Api Call
numbers runs in parallel
Input
1 145 Thread1
3 32 Thread2
4
2
5
After Change Api Call
numbers runs in sequence
Input
1 12345 Thread1
3
4
2
5
const doReprocess = (numbers= []) => {
txnSeqs.forEach(async numbers=> {
setIsReprocessing(numbers, ReprocessStatus.RUNNING);
try {
const result = await axios.post(apiBaseUrl + numbers, {}, {
headers: {
'Content-Type': 'application/json'
}
});
setIsReprocessing(numbers, ReprocessStatus.SUCCESS, result);
} catch (err) {
setIsReprocessing(numbers, ReprocessStatus.ERROR, err.response.data || err);
}
});
}
Is there a way to do this approach? And can you explain it in detail how this can happen?
Thank you