Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@nolanlawson
Created February 18, 2016 15:55
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nolanlawson/28eebac3b91feeeabc6e to your computer and use it in GitHub Desktop.
Save nolanlawson/28eebac3b91feeeabc6e to your computer and use it in GitHub Desktop.
Minimal WebWorker example
<html>
<body>
<h1>Minimal WebWorker example</h1>
<p>Look in the console!</p>
<script src="main.js"></script>
</body>
</html>
var worker = new Worker('worker.js');
worker.postMessage('ping');
worker.onmessage = function (e) {
console.log(e.data); // 'pong'
};
self.onmessage = function (e) {
console.log(e.data); // 'ping'
self.postMessage('pong');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment