Replace array by counter value in throttler

This commit is contained in:
Javier Goizueta 2019-11-19 16:53:49 +01:00
parent 1e0ed7ee17
commit 936b7804de

View File

@ -24,15 +24,15 @@ module.exports = class Throttler extends Transform {
this.bytesPerSecondHistory.shift();
}
const doesNotReachThreshold = [];
let doesNotReachThreshold = 0;
for (const bytesPerSecond of this.bytesPerSecondHistory) {
if (bytesPerSecond <= this.minimunBytesPerSecondThershold) {
doesNotReachThreshold.push(true);
doesNotReachThreshold += 1;
}
}
if (doesNotReachThreshold.length >= this.sampleLength) {
if (doesNotReachThreshold >= this.sampleLength) {
clearInterval(this._interval);
this.pgstream.emit('error', new Error('Connection closed by server: input data too slow'));
}