Skip to content

Instantly share code, notes, and snippets.

@ReidWilliams
Created July 13, 2015 00:48
Show Gist options
  • Save ReidWilliams/495afff4d227cfc6c38b to your computer and use it in GitHub Desktop.
Save ReidWilliams/495afff4d227cfc6c38b to your computer and use it in GitHub Desktop.
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