Skip to content

Instantly share code, notes, and snippets.

@bhavyaw
Created September 6, 2016 13:06
Show Gist options
  • Save bhavyaw/2f7e622db2d40b316fcc16987230f1c0 to your computer and use it in GitHub Desktop.
Save bhavyaw/2f7e622db2d40b316fcc16987230f1c0 to your computer and use it in GitHub Desktop.
var myWorker = new Worker("DetectWakeup.js");
myWorker.onmessage = function (ev) {
if (ev && ev.data === 'wakeup') {
// wakeup here
}
}
// DetectWakeup.js (put in a separate file)
var lastTime = (new Date()).getTime();
var checkInterval = 10000;
setInterval(function () {
var currentTime = (new Date()).getTime();
if (currentTime > (lastTime + checkInterval * 2)) { // ignore small delays
postMessage("wakeup");
}
lastTime = currentTime;
}, checkInterval);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment