npm.io
0.0.10 • Published 9 years ago

controlled-cluster

Licence
ISC
Version
0.0.10
Deps
2
Vulns
0
Weekly
0

The first world solution to spawning child workers

#Installation ###npm i controlled-cluster --save

#Usage The code below will run three processes in parallel. It is your responsibility to check the number of cpus available.

const controlledCluster = require('controlled-cluster');

const processes = [
  (callback) => {
    console.log("running child process");
    setTimeout(() => {
      //do your work here
      let error = false;
      callback(error)
    }, 1000)
  },
  (callback) => {
    console.log("running child process");
    setTimeout(() => {
      //do your work here
      let error = false;
      callback(error)
    }, 1400)
  },
  (callback) => {
    console.log("running child process")
    setTimeout(() => {
      //do your work here
      let error = false;
      callback(error)
    }, 2000)
  }
];

controlledCluster(processes, (err) => {
  if (!err) {
    console.log("They just toss us away like yesterday's jam.");
  } else {
    console.log(err);
    console.log('Have you tried forcing an unexpected reboot?');
  }
})