In essence I have a piece of code somewhat like:
function closeServerGracefully() {
setTimeout(process.exit, 1000);
}
if (failingCondition) {
logger.log('error', 'Fatal error exiting because failingCondition', closeServerGracefully);
}
logger.log('info', 'Everything is ok!');
(The last argument to logger.log
is a callback function that gets called after the message is logged, I'm using winston)
However, if failingCondition
does in fact become true my app outputs this:
Fatal error exiting because failingCondition
Everything is ok!
Then of course it crashes a few moments later because the problem wasn't caught properly.
How can I stop (or pause or kill) the execution of the "main" thread after that if
statement is entered?