UNPKG

backtrace-node

Version:
35 lines 1.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var ClientRateLimit = /** @class */ (function () { function ClientRateLimit(reportPerMin) { this.reportPerMin = reportPerMin; this._reportQueue = []; if (reportPerMin < 0) { throw new Error('ReportPerMinute argument must be greater or equal to zero'); } this._watcherEnable = reportPerMin > 0; } ClientRateLimit.prototype.skipReport = function (report) { if (!this._watcherEnable) { return false; } this.clear(); if (this._reportQueue.length >= this.reportPerMin) { return true; } this._reportQueue.push(report.timestamp); return false; }; ClientRateLimit.prototype.clear = function () { var time = Math.floor(new Date().getTime() / 1000); if (this._reportQueue.length === 0) { return; } if (time - this._reportQueue[0] > 60) { this._reportQueue.length = 0; } }; return ClientRateLimit; }()); exports.ClientRateLimit = ClientRateLimit; //# sourceMappingURL=clientRateLimit.js.map