Skip to content

Instantly share code, notes, and snippets.

@andygup
Last active July 30, 2018 16:21
Show Gist options
  • Select an option

  • Save andygup/e1eb36b64653ce970319610bc2f5d36b to your computer and use it in GitHub Desktop.

Select an option

Save andygup/e1eb36b64653ce970319610bc2f5d36b to your computer and use it in GitHub Desktop.
Simple timer that runs on web worker thread
let time;
onmessage = function(msg){
let value = msg.data;
const interval = value[1];
if(value[0] == "start"){
console.log("Starting timer...");
time = setInterval(function(){
postMessage(true);
}, interval);
}
if(value[0] == "stop"){
console.log("Stopping timer...");
clearInterval(time);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment