an EventEmitter to let workers & master communicate smoothly
varemitter=require('cluster-emitter');emitter.on('event',functioncallback(){//an event callback});emitter.once('event',functioncallbackOnce(){//another event callback});emitter.removeListener('event',callback);emitter.removeListener('event',callbackOnce);emitter.removeAllListeners('event');emitter.emit('event','arg0','arg1');//it varies in master and worker runtime, in master it's the same as sayingemitter.to(['self'].concat(_.map(cluster.workers,function(w){returnw.process.pid;}))).emit('event','arg0','arg1');//as this indicates, the master's emit target by default is everybody, master itself and all active workers//and in worker runtime, it's intepreted as worker itself and masteremitter.to(['self','master'].emit('event','arg0','arg1');//you don't have to use the different `emitTo` method unless you have a different targets set from the default explained above.//but in cause you need, it's also simplified as:emitter.to(['master']).emit('event','arg0','arg1');//use to method to scope the target differently, the value should be an array of pids, or 'master', or 'self'