Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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