Skip to content

Instantly share code, notes, and snippets.

@santhosh17s
Created September 4, 2018 07:07
Show Gist options
  • Save santhosh17s/15a2c46dba84589d6d25378cfdefeaf4 to your computer and use it in GitHub Desktop.
Save santhosh17s/15a2c46dba84589d6d25378cfdefeaf4 to your computer and use it in GitHub Desktop.
//---main.js
if (window.Worker) {
//worker(aURL, options)
const worker = new Worker("worker.js");
worker.onmessage = e => {
const msg = e.data;
console.log(`From Worker thread: ${msg}`);
};
worker.postMessage("Tom!");
//worker.terminate();
}
//---end of Main.js
//----- worker.js
onmessage = e => {
const message = e.data;
console.log(`From Main thread: ${message}`);
postMessage("Cat!");
};
//close();
//----end of worker.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment