Skip to content

maxushuang/SocketIPC

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SocketIPC

Implements IPC with Socket on cluster mode

Demo

const cluster = require('cluster');
const assert = require('assert');
const SocketIPC = require('../SocketIPC');

if (cluster.isMaster) {
  SocketIPC.registerMaster({
    sum(params) {
      return params.reduce((a, b) => a + b, 0);
    },
    exit(code) {
      process.exit(code);
    }
  });
  cluster.fork();
} else {
  SocketIPC.call('sum', [ 1, 2, 3, 4 ]).then(result => {
    assert.equal(result, 10);
    SocketIPC.call('exit', 0);
  }).catch(error => {
    console.error(error);
    SocketIPC.call('exit', 1);
  });
}

About

Implements IPC with Socket on cluster mode

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 97.7%
  • Shell 2.3%