Web Worker

zyip發表於2015-09-30

 

 

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/

 

相關文章