Last active
July 30, 2018 16:21
-
-
Save andygup/e1eb36b64653ce970319610bc2f5d36b to your computer and use it in GitHub Desktop.
Simple timer that runs on web worker thread
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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