I have a function that repeats in NodeJS every minute with the help of the Repeat-package like this:
Repeat(checkCOS).every(10000, 'ms').start.in(5, 'sec');
My problem is that I want the repeater to wait until the callback-function has finished before it starts again. Is this possible to do or do you know any packages that I can use instead?
If your checkOS
is synchronous, then it's guaranteed to be completed before the next timer starts. No need to do anything about this.
If it's async and expects a done
callback, you can do it like this with in-built setTimeout
:
function timer() {
checkOS(() => setTimeout(timer, 1000));
}