1.0.0 • Published 8 years ago
ouroboros-worker v1.0.0
OUROBOROS WORKER
WebWorker to share the code of the main thread
Installation
$ npm install ouroboros-worker
API
run(mainThread: function, workerThread: function): void
Example
const OuroborosWorker = require("ouroboros-worker");
function mainThread(worker) {
worker.postMessage("hello!"); // (1) send to the worker
worker.onmessage = function(e) { // (4) receive from the worker
console.log(e.data); // → good bye!
};
}
function workerThread(self) {
self.onmessage = function(e) { // (2) receive from the main thread
console.log(e.data); // → hello!
self.postMessage("good bye!"); // (3) send to the main thread
}
}
OuroborosWorker.run(mainThread, workerThread);
License
MIT