Closed Brandon-Schefstad closed 1 year ago
I found a solution but it would interfere with other services the web browser may be using with setInterval(). Unassigning myself for now to open the issue up to anyone else!
My Solution:
function handleTimer(duration) {
setInterval(function countdownTimer() {
if(timerObject.active === true){
timerObject.elapsedTime = timerObject.elapsedTime + 1;
console.table('elapsedTime', timerObject.elapsedTime);
// display timer and update task within db
[minutes, seconds] = calculateTimer(duration-1);
displayTimer(minutes, seconds);
}
if (--duration < 0) {
ClearAllIntervals()
displayTimer('00','00');
updateTimerObject();
}
if (timerObject.active === false) {
ClearAllIntervals()
changebuttonColor('red')
}
return countdownTimer
}(), 1000); // <- Interval in ms
changebuttonColor('white')
}
function ClearAllIntervals() {
for (var i = 1; i < 99999; i++)
clearInterval(i);
}
setInterval() automatically imposes a delay on the first function call.