Skip to content

Instantly share code, notes, and snippets.

@shawndumas
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shawndumas/4fdc6305262b212eee45 to your computer and use it in GitHub Desktop.
Save shawndumas/4fdc6305262b212eee45 to your computer and use it in GitHub Desktop.
In-Line Worker
var makeWorker = function (fn) {
var blobURL = URL.createObjectURL(
new Blob(
[ '(', fn.toString(), ')()' ],
{ type: 'application/javascript' }
)
),
worker = new Worker(blobURL);
return worker;
},
worker = makeWorker(function () {
postMessage('ready and wating...');
onmessage = function (evt) {
debugger;
};
});
worker.onmessage = function (evt) {
console.debug('main', evt);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment