
DynWorker
The Talk
DynWorker is a WebWorker library which makes it easier to work with workers (haha).
You no longer need to create a separate file for each different worker... the only
extra file you will ever have to load is dynworker.js
.
DynWorker contains a few utilities to augment your worker. You can easily inject
functions into the worker, run arbitrary code, pass messages containing mixed
data (everything is JSON-encoded), and access DOM storage (local and session).
Development has stopped and DynWorker hasn't been updated in at least three years,
but it still works fine and is used in the wild. Pull requests, bug reports, and
other questions are very welcome. Take care and have fun!
The Code
var worker = new DynWorker();
var worker = new DynWorker("/js/lib/dynworker.min.js");
var worker = new $.worker();
DynWorker.path("path/to/dynworker.js");
var worker = new DynWorker();
worker.inject("funcName", function(arg1, arg2) {
var result = "Do something awesome here";
$.receive(function(e, data) {
});
return result;
});
worker.receive(function(e, data) {
data;
});
worker.run("funcName", arg1, arg2);
worker.run("funcName");
worker.eval("$.send($.ns['funcName']());");
DOM storage
The $.localStorage
API mimics the window.localStorage
API, minus
the array-like interface. Under the hood, all calls are asynchronous, but it
doesn't matter too much. All workers and the main thread use the same DOM
storage. The $.sessionStorage
API is the same.
Inside the worker:
$.localStorage.setItem("key", "data");
$.localStorage.getItem("key", function(data) {
});
The License
DynWorker is licensed under this MIT License.