Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Inspect functions that are part of a promise chain
// Uses underscore.js to wrap a function and upon calling
// prints the function source and the argument.
// Useful for debugging chains of promises.
// USAGE
// var myfunction = function(argument) {...};
// myfunction = inspect(myfunction); // myfunction is now instrumented
var _ = require('underscore');
var util = require('util');
var inspect = function(fnToInspect) {
return _.wrap(fnToInspect, function(fn, resolvedPromise) {
console.log('-------------------------------------------------------------');
console.log('FUNCTION');
console.log(String(fn));
console.log('. . . . . . . . . . . . . . . . . . . . .');
console.log('ARGUMENT');
console.log(util.inspect(resolvedPromise, { colors: true}));
debugger;
return (fn(resolvedPromise));
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.