clusterun
Run tasks in cluster mode easily.
Installation
$ npm install clusterun --save
Usage
clusterun
function Master => Workers => Master
const clusterun registerTask dispatchTask = ; const runner = { // run by Master, to create tasks and dispatch them to Workers}; const handler = { let result; // run by Workers, to process tasks and produce results return result;}; const callback = { // run by Master, to handle task results}; ;
registerTask
function Register a type of task, with a hash-of-task-data function. Called by Master.
;
dispatchTask
function Dispatch a task to Worker. Called by Master.
;
helper functions
name | function | usage |
---|---|---|
whoami | check the role of the current process, and output logs if any | role = whoami() whoami('computing task A') |
ifMaster | run if the current is Master | ifMaster() && doSth() ifMaster(doSth) |
ifWorker | run if the current is Worker | ifWorker() && doSth() ifWorker(doSth) |
License
MIT