Skip to content

Instantly share code, notes, and snippets.

@dshaw
Forked from tmpvar/.gitignore
Created July 12, 2011 07:29
Show Gist options
  • Save dshaw/1077552 to your computer and use it in GitHub Desktop.
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.
/*
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