Skip to content

Commit

Permalink
fix: metrics stats and moving averages types (#915)
Browse files Browse the repository at this point in the history
* fix: give stats initial values

Otherwise the compiler cannot derive the type and thinks `stats.snapshot` returns `{}`

* fix: add type shape to moving averages as well
  • Loading branch information
achingbrain committed Apr 16, 2021
1 parent 55ee332 commit 3d0a79e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/metrics/stats.js
Expand Up @@ -2,7 +2,7 @@
'use strict'

const EventEmitter = require('events')
const Big = require('bignumber.js')
const { BigNumber: Big } = require('bignumber.js')
const MovingAverage = require('moving-average')
const retimer = require('retimer')

Expand All @@ -19,11 +19,17 @@ class Stats extends EventEmitter {

this._options = options
this._queue = []
this._stats = {}

/** @type {{ dataReceived: Big, dataSent: Big }} */
this._stats = {
dataReceived: Big(0),
dataSent: Big(0)
}

this._frequencyLastTime = Date.now()
this._frequencyAccumulators = {}

/** @type {{ dataReceived: MovingAverage[], dataSent: MovingAverage[] }} */
this._movingAverages = {}

this._update = this._update.bind(this)
Expand Down

0 comments on commit 3d0a79e

Please sign in to comment.