diff options
Diffstat (limited to 'public')
-rw-r--r-- | public/timer_worker.js | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/public/timer_worker.js b/public/timer_worker.js new file mode 100644 index 0000000..3d3e79a --- /dev/null +++ b/public/timer_worker.js @@ -0,0 +1,24 @@ +let timerInterval = null; + +function setTimerInterval() { + if (!timerInterval) { + timerInterval = setInterval(function() { + postMessage("timerTick"); + }, 10); + } +} + +function clearTimerInterval() { + clearInterval(timerInterval); + timerInterval = null; +} + +onmessage = function(event) { + if ("run_flag" in event.data) { + if (event.data["run_flag"]) { + setTimerInterval(); + } else { + clearTimerInterval(); + } + } +} |