Web threading made easy
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 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!
// If the library is in the current dir and// is named dynworker.js, this works:var worker = ;// Otherwise you need to specify a filename,// but it needs to be on the same domain.var worker = "/js/lib/dynworker.min.js";// You can have a shortcut with Ender:var worker = new $;// You can also modify the default path once and for all:DynWorker;var worker = ;// The function is namespaced under $.ns// inside the worker.worker;// The callback gets back the raw event and the// parsed dataworker;// The #run function wraps the function call in a// $.send() so the return value of the// function is sent up.worker;// Hence, these two are equivalent:worker;worker;
$.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
$.sessionStorage API is the same.
Inside the worker:
DynWorker is licensed under this MIT License.