diff --git a/packages/measured-core/lib/metrics/Meter.js b/packages/measured-core/lib/metrics/Meter.js index 183b0e3..4014549 100644 --- a/packages/measured-core/lib/metrics/Meter.js +++ b/packages/measured-core/lib/metrics/Meter.js @@ -22,6 +22,10 @@ class Meter { constructor(properties) { this._properties = properties || {}; this._initializeState(); + + if (!this._properties.keepAlive) { + this.unref(); + } } /** @@ -164,6 +168,7 @@ module.exports = Meter; * @type {Object} * @property {number} rateUnit The rate unit. Defaults to 1000 (1 sec). * @property {number} tickInterval The interval in which the averages are updated. Defaults to 5000 (5 sec). + * @property {boolean} keepAlive Optional flag to unref the associated timer. Defaults to `false`. * @example * const meter = new Meter({ rateUnit: 1000, tickInterval: 5000}) */ diff --git a/packages/measured-core/lib/metrics/Timer.js b/packages/measured-core/lib/metrics/Timer.js index 14cd39a..3e07aae 100644 --- a/packages/measured-core/lib/metrics/Timer.js +++ b/packages/measured-core/lib/metrics/Timer.js @@ -43,6 +43,11 @@ class Timer { this._meter = properties.meter || new Meter({}); this._histogram = properties.histogram || new Histogram({}); this._getTime = properties.getTime; + this._keepAlive = !!properties.keepAlive; + + if (!properties.keepAlive) { + this.unref(); + } } /** @@ -127,4 +132,5 @@ module.exports = Timer; * @property {Meter} meter The internal meter to use. Defaults to a new {@link Meter}. * @property {Histogram} histogram The internal histogram to use. Defaults to a new {@link Histogram}. * @property {function} getTime optional function override for supplying time to the {@link Stopwatch} + * @property {boolean} keepAlive Optional flag to unref the associated timer. Defaults to `false`. */ diff --git a/packages/measured-reporting/lib/reporters/Reporter.js b/packages/measured-reporting/lib/reporters/Reporter.js index 98b6ebe..96fb409 100644 --- a/packages/measured-reporting/lib/reporters/Reporter.js +++ b/packages/measured-reporting/lib/reporters/Reporter.js @@ -92,7 +92,8 @@ class Reporter { * @type {Logger} * @protected */ - this._log = options.logger || consoleLogLevel({ name: 'Reporter', level: options.logLevel || 'info', prefix: prefix }); + this._log = + options.logger || consoleLogLevel({ name: 'Reporter', level: options.logLevel || 'info', prefix: prefix }); /** * The default reporting interval, a number in seconds.