Skip to content

Instantly share code, notes, and snippets.

@titarenko
Created April 10, 2014 15:00
Show Gist options
  • Select an option

  • Save titarenko/10391325 to your computer and use it in GitHub Desktop.

Select an option

Save titarenko/10391325 to your computer and use it in GitHub Desktop.
Exit
var log = require('../core/log');
var memwatch = require('memwatch');
function exit () {
// temporal failure, user is invited to restart
// (according to http://stackoverflow.com/a/1535733)
process.exit(75);
}
exit.whenUncaughtException = function () {
process.on('uncaughtException', function (error) {
exit();
});
return exit;
};
exit.whenMemoryLimit = function (limit) {
memwatch.on('stats', function (info) {
if (info.current_base > limit) {
log.info('Exceeded memory limit.', info.current_base.toString(), '>', limit.toString())
exit();
}
});
return exit;
}
module.exports = exit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment