Skip to content

Instantly share code, notes, and snippets.

@sTiLL-iLL
Created February 1, 2015 11:44
Show Gist options
  • Save sTiLL-iLL/9ee86b4952247b5c5a03 to your computer and use it in GitHub Desktop.
Save sTiLL-iLL/9ee86b4952247b5c5a03 to your computer and use it in GitHub Desktop.
Spin a worker from within the original html/js file!
function worker() {
setInterval(function() {
postMessage({foo: "bar"});
}, 1000);
}
var code = worker.toString();
code = code.substring(code.indexOf("{")+1, code.lastIndexOf("}"));
var blob = new Blob([code], {type: "application/javascript"});
var worker = new Worker(URL.createObjectURL(blob));
worker.onmessage = function(m) {
console.log("msg", m);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment