Skip to content

Instantly share code, notes, and snippets.

@deebloo
Last active June 4, 2016 19:06
Show Gist options
  • Save deebloo/94dcaaed24396ebe280734bf96b8b73f to your computer and use it in GitHub Desktop.
Save deebloo/94dcaaed24396ebe280734bf96b8b73f to your computer and use it in GitHub Desktop.
// New workers is created for a link to an external js file
var myWorker = new Worker('web-worker.js');
// function to fire when a message is sent from the worker.
myWorker.onmessage = function (e) {
console.log(e.data); // HELLO WORLD
}
// send a message to the worker
myWorker.postMessage('hello world');
// When the web worker receives a worker. look at the data and uppercase it, and send it back
self.onmessage = function (e) {
self.postMessage(e.data.tpUpperCase());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment