I have an forEach loop that make an async call to an API:
array.forEach(async (item) => {
await callAnApi(item)
})
I want to make this loop wait 1 second between the items - because the API is getting sattured.
We need something like this:
array.forEach((item) => {
setTimeout(async () => {
await callAnApi(item)
},1000)
})
That way it doesn't work because the whole loop runs in the "same time" so every call will be fired "in the same time" after 1 second.
I already have searched for dozens of answers but none of them have solve this simple problem.