domainit

Wrap a function within the confines of a domain using the simple callback form you know and love.

npm install domainit
8 downloads in the last week
16 downloads in the last month

domainit - wrap a function with the safety of a domain

Wrap a function with the warm comfort of a node domain using standard callbacks.

Build Status Dependency Status

var assert = require('assert');
var domainit = require('domainit');

function unsafe(cb) {
  process.nextTick(function () {
    throw new Error('Oops!');
  });
}

var safe = domainit(unsafe);
safe(function (err) {
  assert(err);
  assert(err.message === 'Oops!');
});

warning for node < v0.9.5

Versions of Node before v0.9.5 raise uncaughtException events despite errors being handled within a domain. You shouldn't need to handle uncaughtException if you are working with domains.

Some testing frameworks, like mocha, bind to the uncaughtException event. This will wrongly cause tests to fail when errors occur within a domain on Node versions < 0.9.5.

Check out the relevant issue on GitHub.

npm loves you