slavery

Convenience module for forking and communicating with child processes in Node.js

Usage no npm install needed!

<script type="module">
  import slavery from 'https://cdn.skypack.dev/slavery';
</script>

README

slavery

Convenience module for forking and communicating with child processes in Node.js

Build Status Coverage Status Dependency Status

Installation

In your project path:

npm install slavery --save

Usage

slave

setInterval(function () {}, Number.MAX_VALUE); // keep slave alive

function calc(a, b) {
    return a + b;
}

process.on('message', function (message) {
    switch (message.task) {
        case 'calc':
            setTimeout(function () {
                process.send(['done', null, calc.apply(null, message.args)]);
            }, 10);
            break;
    }
});

master

var slavedriver = require('slavery');

slavedriver.whip('pathToSlave').once('done', function (err, result) {
    assert.equal(result, 3);
    this.process.kill('SIGKILL');
}).process.send({
    task: 'calc',
    args: [1, 2]
});

More usage examples here.