Skip to content

Instantly share code, notes, and snippets.

@johannish
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johannish/52c6d111201358b7ceac to your computer and use it in GitHub Desktop.
Save johannish/52c6d111201358b7ceac to your computer and use it in GitHub Desktop.
Node.js console.log synchronous
console.log('stdout._type:', process.stdout._type);
process.nextTick(function() {
process.exit(123);
});
process.on('exit', function(code) {
process.nextTick(function() {
console.log('This does not run, as the docs say.');
});
console.log('This should not run if proces.stdout._type is pipe.');
});
console.log("isTTY: ", process.stdout.isTTY);
// per https://nodejs.org/api/console.html, I expect this time to be before both x and y if terminal, and after if piped.
// invalid: parameter to console.log gets evaluated instantly, regardless of whether the log() function blocks or not.
console.log("Logged at: " + process.hrtime());
x = process.hrtime();
y = (function() {return process.hrtime()})();
console.log("x: " + x);
console.log("y: " + y);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment