block by bollwyvl b34ffe2f40d64f3aae0f

d3.worker: a d3-inspired API for webworkers

d3.worker

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.

API exploration

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

TODO

d3.worker.js