Node.js callback helper with proper domain error handling
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
examples
test
.gitignore
README.md
callable.js
package.json

README.md

Callable

Helps fix callback issue discussed here: https://github.com/joyent/node/issues/4702. Tests, further examples, and description about the issue this utility solves are coming.

Installation

npm install callable

Usage

Append .callable() to your function function(){}.callable() or wrap it: callable(function(){})

require("callable");

var d = domain.create();
d.run(function() {
  var request = http.request({ hostname: "google.com", port: 80, method: "HEAD" }, function(response) {
    throw new Error("An exception from the response handler");
  }.callable().bind(this));
  request.end();

  d.on("error", function(error) {
    console.log("domain caught " + error);
    d.dispose();
  });
});

Chaining

Both approaches can be chained with other functions such as .bind()

Append

function(){}.callable().bind(this);
function(){}.bind(this).callable();

Wrap

callable(function(){}).bind(this);
callable(function(){}.bind(this));