Tiny WebWorker for Server
require()
is available for flexible inline Worker scripts.
The worker script:
self.onmessage = function (ev) {
postMessage(ev.data);
};
The core script:
var Worker = require("tiny-worker");
var worker = new Worker("repeat.js");
worker.onmessage = function (ev) {
console.log(ev.data);
worker.terminate();
};
worker.postMessage("Hello World!");
var Worker = require("tiny-worker");
var worker = new Worker(function () {
self.onmessage = function (ev) {
postMessage(ev.data);
};
});
worker.onmessage = function (ev) {
console.log(ev.data);
worker.terminate();
};
worker.postMessage("Hello World!");
Message handler, accepts an Event
Error handler, accepts an Event
Adds an event listener
Broadcasts a message to the Worker
Terminates the Worker
Copyright (c) 2015 Jason Mulligan Licensed under the BSD-3 license