I have a function that handles sending requests when a button is clicked, however the requests just get "blasted" and I want them to be a bit spaced out in time, say 500ms apart.
Here is what I have tried:
async function SendRequests() {
requestsToSend.forEach(async (request) => {
request.Send();
await new Promise((resolve) => setTimeout(resolve, 500));
});
}
But it doesn't work the requests still get blasted. I have seen this approach in another answer to a similar question, and I have also used it in my own code on the NodeJS side and it works there, but I can't get it to work on the React side.
I have also tried this:
function SendRequests() {
requestsToSend.forEach((request) => {
setTimeout(()=> { request.Send(); }, 500)
});
}
And it kinda works, but they still get blasted. What I am guessing is happening here is that, all of the setTimeouts get queued and they just count out at the same time.