JSFiddle - React, Tailwind, and code Playground
by the94air
HTML
<p>CHECK CONSOLE</p>
<EM>wanting a STOP function that i can call from outside</EM>
JavaScript
function countdownTimer(
callbackFunc,
countLength,
iteratorFunc,
iteratorMilliseconds
) {
let numberofIterations = countLength;
const onInterval = () => {
// do something at each interval if required
iteratorFunc(numberofIterations);
if (numberofIterations === 0) {
stopInterval();
// do something after total of intervals stops (countLength has passed)
// run loadmore call
callbackFunc();
}
numberofIterations--;
};
const stopInterval = () => {
clearInterval(interval);
};
const interval = setInterval(onInterval, iteratorMilliseconds);
}
function sendEmailCallback() {
console.log("fired it");
return console.log("test callback function - send message");
}
function countDown(numberofIterations) {
return console.log(numberofIterations);
}
countdownTimer(sendEmailCallback, 3, countDown, 1000, true);