Wrap a function within the confines of a domain using the simple callback form you know and love.
JavaScript
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
test
.gitignore
.travis.yml
README.md
assert.js
index.js
mocha_test.js
package.json

README.md

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.