Web workers¶llel.js html5lt

  • Published on
    23-Aug-2014

  • View
    269

  • Download
    10

DESCRIPTION

2014/06/05

Transcript

Web Workers & Parallel.js (function() { let me = { name : , twitter : @banana_umai , as : Server Side Engineer , belogns_to : } })(); Web Workers API http://www.hcn.zaq.ne.jp/___/WEB/Workers-ja.html API http://www.hcn.zaq.ne.jp/___/WEB/Workers-ja.html DOM UI var worker = new Worker("js/worker.js"); worker.onmessage = function(event) { console.log(event.data); }; worker.postMessage(msg); self.onmessage = function(event) { loadScripts( proc.js ); postMessage(procWithData(event.data)); } var worker = new Worker("js/worker.js"); worker.onmessage = function(event) { console.log(event.data); }; worker.postMessage(msg); self.onmessage = function(event) { loadScripts( proc.js ); postMessage(procWithData(event.data)); } var worker = new Worker("js/worker.js"); worker.onmessage = function(event) { console.log(event.data); }; worker.postMessage(msg); self.onmessage = function(event) { loadScripts( proc.js ); postMessage(procWithData(event.data)); } var worker = new Worker("js/worker.js"); worker.onmessage = function(event) { console.log(event.data); }; worker.postMessage(msg); self.onmessage = function(event) { loadScripts( proc.js ); postMessage(procWithData(event.data)); } var worker = new Worker("js/worker.js"); worker.onmessage = function(event) { console.log(event.data); }; worker.postMessage(msg); self.onmessage = function(event) { loadScripts( proc.js ); postMessage(procWithData(event.data)); } var worker = new Worker("js/worker.js"); worker.onmessage = function(event) { console.log(event.data); }; worker.postMessage(msg); self.onmessage = function(event) { loadScripts( proc.js ); postMessage(procWithData(event.data)); } var worker = new Worker("js/worker.js"); worker.onmessage = function(event) { console.log(event.data); }; worker.postMessage(msg); self.onmessage = function(event) { loadScripts( proc.js ); postMessage(procWithData(event.data)); } var worker = new Worker("js/worker.js"); worker.onmessage = function(event) { console.log(event.data); }; worker.postMessage(msg); self.onmessage = function(event) { loadScripts( proc.js ); postMessage(procWithData(event.data)); } var worker = new Worker("js/worker.js"); worker.onmessage = function(event) { console.log(event.data); }; worker.postMessage(msg); self.onmessage = function(event) { loadScripts( proc.js ); postMessage(procWithData(event.data)); } Parallel.js http://adambom.github.io/parallel.js/ var data = ; var p = new Parallel(data); p.spawn(function (data) { // some proc with data running in background return result; }).then(function (result) { // some proc with result }); map/reduce var data = [1, 2, 3, 4]; var p = new Parallel(data); p.map(function (datum) { return datum * 2; }).reduce(function (mappedData) { return mappedData[0] + mappedData[1]; }).then(function (reduced) { console.log(mappedData); // 20 });