I hate functions and re-writing callbacks by "intercepting" them and passing the original along. This is simple: it uses an existing function, exec
, and doesn't open it up. Its callback arguments are passed into results.exec
. There's just a lot of overhead here. I was wondering if there's an easier way, using the async
library or not.
function execModify(command, manipulators, callback) {
var exec = childProcess.exec;
return async.auto({
"exec": async.apply(exec, command),
}, function(err, results) {
if (err) return callback(err);
var value = results.exec[0];
if (typeof manipulators == "function") return manipulators(null, value);
if (manipulators.length == 0) return callback(null, value);
_.each(manipulators, function(manipulator) {
value = manipulator(value);
});
return callback(null, value);
});
};