Skip to content

Instantly share code, notes, and snippets.

@wittawasw
Last active August 29, 2015 14:02
Show Gist options
  • Save wittawasw/a2fe3500515727ab24a7 to your computer and use it in GitHub Desktop.
Save wittawasw/a2fe3500515727ab24a7 to your computer and use it in GitHub Desktop.
Web Worker concept
(function() {
var worker = new Worker("js/worker.js");
worker.onmessage = function(e) {
alert("worker: " + e.data);
}
worker.postMessage('start');
// send msg the worker.
})();
<!DOCTYPE html>
<html>
<head>
<script src="js/application.js"></script>
</head>
<body>
</body>
</html>
self.onmessage = function(e) {
// free to do anything here.
self.postMessage('Hello ' + e.data);
// return msg to parent.
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment