Created
February 18, 2016 15:55
-
-
Save nolanlawson/28eebac3b91feeeabc6e to your computer and use it in GitHub Desktop.
Minimal WebWorker example
This file contains 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
<html> | |
<body> | |
<h1>Minimal WebWorker example</h1> | |
<p>Look in the console!</p> | |
<script src="main.js"></script> | |
</body> | |
</html> |
This file contains 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
var worker = new Worker('worker.js'); | |
worker.postMessage('ping'); | |
worker.onmessage = function (e) { | |
console.log(e.data); // 'pong' | |
}; |
This file contains 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
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