debug-promise
v0.2.5
Published
Debug output outstanding promises, progress, errors, and resolution times.
Downloads
6
Maintainers
Readme
debug-promise
debug-promise consumes promises and outputs logs showing their progress, their resolution or rejection, and makes state dumps showing all promises that have not settled.
How?
debug-promise can consume any type of promises, but for the sake of this example we'll use one from Kriskowal's Q Library.
var Q = require('Q');
var debug = require('debug-promise')('test-logger');
var defer = Q.defer();
debug(defer.promise, 'arbitrary promise name for logging');
// sometime in the future resolve that promise
setTimeout(function () {
defer.resolve();
}, 10000);
debug-promise returns the original promise so you can easily chain like so:
debug(Q.resolve('value'), 'value promise').then(function (res) {
// res === 'value'
});
Example output
debug-promise:test-logger
--- OUTSTANDING PROMISES ---
arbitrary promise label 1 0 seconds
----------------------------
+0ms
debug-promise:test-logger
--- OUTSTANDING PROMISES ---
arbitrary promise label 1 0.002 seconds
arbitrary promise label 2 0.001 seconds
----------------------------
+3ms
debug-promise:test-logger
--- OUTSTANDING PROMISES ---
arbitrary promise label 1 0.003 seconds
arbitrary promise label 2 0.001 seconds
arbitrary promise label 3 0 seconds
----------------------------
+0ms
debug-promise:test-logger
--- OUTSTANDING PROMISES ---
arbitrary promise label 1 0.003 seconds
arbitrary promise label 2 0.001 seconds
arbitrary promise label 3 0 seconds
arbitrary promise label 4 0 seconds
----------------------------
+0ms
debug-promise:test-logger
--- OUTSTANDING PROMISES ---
arbitrary promise label 1 0.003 seconds
arbitrary promise label 2 0.001 seconds
arbitrary promise label 3 0 seconds
arbitrary promise label 4 0 seconds
arbitrary promise label 5 0.001 seconds
----------------------------
+1ms
debug-promise:test-logger progress (100): arbitrary promise label 1 0.004
+0ms
debug-promise:test-logger progress (undefined): arbitrary promise label 1 0.004
+1ms
debug-promise:test-logger resolved (undefined): arbitrary promise label 1 1.006
+1s
debug-promise:test-logger
--- OUTSTANDING PROMISES ---
arbitrary promise label 2 1.004 seconds
arbitrary promise label 3 1.003 seconds
arbitrary promise label 4 1.003 seconds
arbitrary promise label 5 1.003 seconds
----------------------------
+0ms
debug-promise:test-logger rejected (undefined): arbitrary promise label 2 2.007
+1s
debug-promise:test-logger
--- OUTSTANDING PROMISES ---
arbitrary promise label 3 2.006 seconds
arbitrary promise label 4 2.006 seconds
arbitrary promise label 5 2.006 seconds
----------------------------
+0ms
debug-promise:test-logger resolved (undefined): arbitrary promise label 3 3.001
+995ms
debug-promise:test-logger
--- OUTSTANDING PROMISES ---
arbitrary promise label 4 3.002 seconds
arbitrary promise label 5 3.002 seconds
----------------------------
+1ms
debug-promise:test-logger rejected ('asdf'): arbitrary promise label 4 4.001
+1s
debug-promise:test-logger rejected ('asdf'): arbitrary promise label 5 4.002
+0ms
debug-promise:test-logger
--- OUTSTANDING PROMISES ---
arbitrary promise label 5 4.002 seconds
----------------------------
+0ms
debug-promise:test-logger
--- OUTSTANDING PROMISES ---
----------------------------
+0ms