Created
July 13, 2015 00:48
-
-
Save ReidWilliams/495afff4d227cfc6c38b to your computer and use it in GitHub Desktop.
Inspect functions that are part of a promise chain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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