I would like to make axios request to an API in a loop and pause the sending of new requests based on a response header of the API.
example code would be like this:
for(i in overallRequests) {
const res = await axios(config);
if (res.headers["ratelimit"] < 100) {
return new Promise(resolve => setTimeout(resolve, 60000));
}
}
this is not working as intended.
Try for of loop instead of for in
for(i of overallRequests) {
const res = await axios(config);
if (res.headers["ratelimit"] < 100) {
return new Promise(resolve => setTimeout(resolve, 60000));
}
}