Dispatcher for Node.js
Author: Rudolph-Miller
-
How to use
Dispatcher = 'node-dispatcher' dispatcher = new Dispatcher dispatcher.use *id*, *function* if dispatcher.isMaster dispatcher.fork() dispatcher.pushQ *id*, *target* dispatcher.on 'result', (message) -> message.result = *function*( *target* )
-
Master
- Properties
- isMaster -> if dispathcer is master return true else false.
- isWorker -> if dispathcer is worker return true else false.
- pid -> return pid of instance.
- Methods
- fork() -> make instance of worker.
- forks(n) -> make n instances of worker.
- use(id, function) -> register id and function (typeof id is 'string').
- pushQ(id, target) -> push id and target on Queue.
- remove() -> exit all workers which is working.
- Events
- on 'pullTask',(message) -> message.pid is the pid of worker which pull task.
- on 'result', (message) -> message.result is result of task, message.task is task.
- on 'workerStart', (message) -> message.pid is the pid of starting worker.
- Properties
-
Worker You can not customize Worker or touch on them, because Workers are precious for them and do not push everythig against them.