callback tools

node.js callback tools

Tools for simplifying node.js callback style programming.

Returns function(err, result) that calls cb(err) if err != null and else calls func(result, cb).

Simplifies this case:

function (cb) {
someAsyncCall(function (errresult) {
if (err != null) {
else {
cb(null, doSomethingWithResult(result));
} // too many lines of code 

to this one:

var errh = require('ncbt').errh;
function (cb) {
someAsyncCall(errh(function (resultcb) {
cb(null, doSomethingWithResult(result)); // much nicer 
}, cb);

Returns function(err) that calls cb(err) shrinking any other arguments.

Useful for getting rid of insert or update results when querying db.

Like errh.noResult(cb), but calls cb(err, null).