Skip to content

Instantly share code, notes, and snippets.

@famasya
Created April 17, 2017 13:48
Show Gist options
  • Save famasya/b64e6110f9beb94261816c1a709323ba to your computer and use it in GitHub Desktop.
Save famasya/b64e6110f9beb94261816c1a709323ba to your computer and use it in GitHub Desktop.
Periodically checking token validity by web worker
self.addEventListener('message', function(e){
setInterval(function(){
self.postMessage("Checking token "+e.data);
// Do AUTH checking here...
}, 1000);
}, false);
<!DOCTYPE html>
<html>
<head>
<title>Web Worker</title>
</head>
<body>
</body>
<script type="text/javascript">
if(window.Worker){
var worker = new Worker('task.js');
var token = "j3l21hdsakh321kjhbdsaiuoi321dlasopinac";
worker.addEventListener('message', function(e){
// process returned data
console.log('He said : '+e.data);
}, false);
worker.postMessage(token);
}
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment