-
-
Save dshaw/1077552 to your computer and use it in GitHub Desktop.
A console.log implementation that plays "nice" with large amounts of data. Keeps node alive until the output has flushed to screen.
This file contains hidden or 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
/* | |
A console.log that won't leave you hanging when node exits | |
*/ | |
console.log = function(d) { | |
var res = process.stdout.write(d + '\n'); | |
// this is the first time stdout got backed up | |
if (!res && !process.stdout.pendingWrite) { | |
process.stdout.pendingWrite = true; | |
// magic sauce: keep node alive until stdout has flushed | |
process.stdout.once('drain', function () { | |
process.stdout.draining = false; | |
}); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment