Skip to content

Commit

Permalink
Merge pull request #64 from tuckbick/unref
Browse files Browse the repository at this point in the history
feat: Add optional `keepAlive` option to Meter and Timer
  • Loading branch information
csabapalfi authored May 24, 2019
2 parents 45eaaaa + d2b5590 commit 6283bf0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions packages/measured-core/lib/metrics/Meter.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class Meter {
constructor(properties) {
this._properties = properties || {};
this._initializeState();

if (!this._properties.keepAlive) {
this.unref();
}
}

/**
Expand Down Expand Up @@ -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})
*/
Expand Down
6 changes: 6 additions & 0 deletions packages/measured-core/lib/metrics/Timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

/**
Expand Down Expand Up @@ -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`.
*/
3 changes: 2 additions & 1 deletion packages/measured-reporting/lib/reporters/Reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 6283bf0

Please sign in to comment.