blob: c62679a389dcbe933f36a0765523db05f54b57f6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
let timerInterval = null;
let timerTimeout = 10;
function setTimerInterval() {
if (!timerInterval) {
timerInterval = setInterval(function() {
postMessage("timerTick");
}, timerTimeout);
}
}
function clearTimerInterval() {
clearInterval(timerInterval);
timerInterval = null;
}
onmessage = function(event) {
if ("run_flag" in event.data) {
if (event.data["run_flag"]) {
setTimerInterval();
} else {
clearTimerInterval();
}
} else if ("set_timeout" in event.data) {
timerTimeout = event.data["set_timeout"];
}
}
|