Skip to content

jcrugzz/fork

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fork

build status

A simple module that gives a clean request/response api for dealing with a child_process that you want to fork. It comes with built in retry support using back for backoff to try and ensure determinism. Works best when used with forkee for the child process.

install

npm install fork --save

Example Usage

//
// This could also just be a path but we encourage module use :)
//
var childToFork = require.resolve('myChildProcModule');
var Fork = require('fork');
//
// Specify retries and backoff (useful for network based operations);
//
var message = { action: 'start', whatever: 'blahblah' };

var fork = new Fork({
  path: childToFork,
  retries: 3,
  backoff: true})
  .fork(message)
  .on('error', function(err) { console.error(err) })
  .on('retry', function () { console.log('retrying')})
  .on('response', function (message) { console.dir(message) });

//
// If the `forkee` child process sends an event, it gets emit on the `fork` instance.
// If the forkee instance sent a `website:fetched` message
//
fork.on('website:fetched', function (message) {
  // Do something with `message` object like log it or dispatch to an external
  // service
});

//
// You can also use a simple callback api on the `start`/`fork` method!
//
var fork2 = new Fork(childToFork).start(message,
  function(err, returnMessage) {
  if (err) {
    return console.error(err);
  }
  console.dir(returnMessage);
});

About

Request/Response process forker

Resources

License

Stars

Watchers

Forks

Packages

No packages published