From c35287ce7a5a28bb39d4731eca6fc0716cc46524 Mon Sep 17 00:00:00 2001 From: Maciej Winnicki Date: Wed, 28 Nov 2018 10:13:32 +0100 Subject: [PATCH] Fix runtime stats sending --- index.js | 5 +++-- lib/stats.js | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index e1bab40..6546403 100644 --- a/index.js +++ b/index.js @@ -157,8 +157,9 @@ if (program.daemonize) { * Handle signals */ const cleanExit = () => { - stats.timeEnd('runtime', 'runtime'); - process.exit(); + stats.timeEnd('runtime', 'runtime', () => { + process.exit(); + }); }; process.on('SIGINT', cleanExit); process.on('SIGTERM', cleanExit); diff --git a/lib/stats.js b/lib/stats.js index 3e6b8a5..9731d1e 100644 --- a/lib/stats.js +++ b/lib/stats.js @@ -54,12 +54,12 @@ Stats.prototype.time = function time(category, action) { this.timer[category][action] = Date.now(); }; -Stats.prototype.timeEnd = function timeEnd(category, action) { +Stats.prototype.timeEnd = function timeEnd(category, action, cb) { if (!this.tracker) { return; } - this.tracker.timing(category, action, Date.now() - this.timer[category][action]).send(); + this.tracker.timing(category, action, Date.now() - this.timer[category][action]).send(cb); }; module.exports = enabled => new Stats(enabled);