-
-
Save dhilip89/e233ffa26633f8cb96d6491ebaa2ddc8 to your computer and use it in GitHub Desktop.
Create web workers without a separate worker JS files.
Source: http://jsbin.com/owogib/8/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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