I have nodejs app that needs a few infinite loops which call async functions. I was considering implementing the following:
async function execute1() {
...do some async work...
}
async function execute2() {
...do some async work...
}
setInterval(execute1, 500)
setInterval(execute2, 500)
My concern is that if the async functions will take a long time to complete, the open references will pile up and this can result in a memory crash down the line.
setInterval
isn't the right tool because it's unaware of promises and can't maintain correct control flow.
It can be async
function with infinite loop:
async function execute1() {
while (true) {
await new Promise(resolve => setTimeout(resolve, 500));
// ...do some async work...
}
}
execute1();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With