I am trying to loop an array and delay the loop if the request is still processing and continue the loop when the request is done.
Here is what my codes look like
// request is from redux
for (var i = 0; i < request.length; i++) {
let k = i;
setTimeout(function () {
// requestInProgress came from redux so it will re-render when the value is updated
if(!requestInProgress){
// proceed the loop
} else {
// I want to delay the loop by giving more timeout but not sure how it should be done here
}
}, 5000 * (k + 1));
}
Currently, I don't have anything in else statement. I just thought of adding more time delay there but not sure if it can be done that way. Any help would be much appreciated. Thank you.