WebWorkers are silly powerful, but also kinda clunky.
d3.worker
aims to make the whole experience much nicer, by hiding some of the implementation details.
var worker = d3.worker()
.message("add", function(a, b){
// this will get `toString`ed.. so no cheating!
// `this` is the wrapped webworker... you can get at it with this.worker
// the handlers are installed on the `message` object
return this.message.sum(a + b);
})
.on("sum", function(sum){
// `this` is still the worker... but outside
return console.log("RESULT", sum);
});
// this still feels weird...
worker();
// possible APIs
worker.message.add(1, 1);
worker.add(1, 1);
d3.worker().dependencies("./d3.js")
d3.worker().setup(function(){})