WorkerIO
Messaging pub/sub api for web workers includes Parallel libary
New: Parallel functionality - with an ability to send job and split it to sub workers More details below
The new parallel libary including those features:
- pub/sub - send and get messages from the job during proccessing
- waitAny - get a notification on the caller side when a sub worker finish its job with the result of the job.
- WaitAll - get a notification on the caller side when a the whole job is finshed includes the result of the job
- broadcasting - broadcasting message to the whole wrokers
- cancelAll - close the workers
- limiting worker numbers- (in the next few days) an ability to limit the number of workers that will handle the job
More details below under the user instructions section
Usage instructions:
worker:
-
create a worker on a separated file
-
import workerIO lib to your worker using
importScripts()
then -
init workerIO
var yourWorkerName = IO.Worker();
-
call to start method you should recive your socket instance for communicating with the caller side
yourWorkerNamestart{ \\body ... };
- within the
start
function you can recive messages by calling toon
function
socket
- sending messages using
emit
functionsocket.emit("messageName","Data")
- full worker sample code
\\"testWorker.js" file { ; var testWorker = IO; testWorkerstart{ socket socket } Worker;
caller:
- init workerIO caller
var yourCallerName = IO.Reciver("testWorker.js");
- start processing the job by calling to
start
function
yourCallerNamestart{ ... }
-
within the
start
function you can recive messages by calling toon
functionjavascript socket.on("messageName",callbackFunction(Data))
-
sending messages using
emit
functionjavascript socket.emit("messageName","Data")
-
full caller sample code
var io= IO; iostart{ socket; socket; };
parallel:
- init parallel job is done using
var parallel= IO.Parallel("workerUnit.js");
- in order to start a new job you should use
parallel
- then you can register to the following events
- on waitAny callback you will get the workerName and the result of the worker
- on waitAll callback you will get the results from all the workers
parallel
- sending brodacast meesage to all of the workers is done using
parallel.broadcast.emit("messageTopic",data)
- you can also cancel to job during proccessing by using cancelAll
parallel.cancelAll();
full parallel example
caller:
//imitJob var parallel= IO; //Setting Job and creating wrokers parallel; ; { //removing all the jobs parallel; }
worker:
{ ; var inter= null ; var testWorker = IO; testWorkerstart{ socket; ; { inter = ; } }};