Neutral Political Machine
Have opinions about JavaScript? We want to hear them. Take the 2018 JavaScript Ecosystem Survey »

ipc-messenger

1.0.0 • Public • Published

ipc-messenger

A package for node.js that helps send messages to processes created by cluster.

Example

(function() {
  var cluster = require('cluster')
  var http = require('http')
  var ipcm = require('ipc-messenger')
 
  var numCPUs = require('os').cpus().length
 
  var masterReceiver = function(message) {
    console.log('masterReceiver:', message)
  }
 
  var workerReceiver = function(message) {
    console.log('workerReceiver:', message)
  }
 
  var handler = function(request, response) {
    ipcm.messageMaster('message master')
    ipcm.messageSiblings('message siblings')
    ipcm.messageWorkers('message workers')
    response.writeHead(200)
    response.end('Done')
    return
  }
 
  if (cluster.isMaster) {
    var worker
    for (var i = 0; i < numCPUs; i++) {
      worker = cluster.fork()
      ipcm.register(worker, masterReceiver)
    }
  }
  else {
    ipcm.register(process, workerReceiver)
    http.createServer(handler).listen(8000)
  }
})()

install

npm i ipc-messenger

Downloadsweekly downloads

2

version

1.0.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability