Skip to content

owenkellogg/domain-supervisor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Domain Supervisor

Start co-routines bounded by domains for parallel error handling.

Inspired by Erlang Supervisor and Process classes that enable fault- tolerant parallel applications by isolating co-routines from each other, thus preventing exceptions in co-routines from crashing the main nodejs process.

Installation

npm install domain-supervisor

Usage

var Supervisor = require('domain-supervisor').Supervisor;
var Process = require('domain-supervisor').Process;

var proc = new Process(myCoRoutine);
var supervisor = new Supervisor();

supervisor.run(proc, function(error, restart, crash) {
  if (true) {
    console.log('Handling error:', error.stack);
    console.log('restarting...');
    restart();
  } else {
    // never crash the unix process, but it is an option
    crash(error);
  }
});

function myCoRoutine() {
  var loops = 0;
  setInterval(function() {
    console.log('valuably crunching data');
    if (loops > 5) throw new Error('some terrible exception!'); 
  }, 1000);
}

About

Run co-routines in domains, for robust parallel exception handling. Inspired by Elixir Supervisor and Process

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published