inline worker

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);
};

  

http://www.sitepoint.com/multi-threading-javascript/

 

http://keithwhor.github.io/multithread.js/

 

相关文章:

  • 2021-10-22
  • 2021-08-15
  • 2022-12-23
  • 2021-06-12
  • 2022-02-23
  • 2021-09-20
猜你喜欢
  • 2021-07-30
  • 2017-11-28
相关资源
相似解决方案