Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class Saturn {
this.onReportLogs = this.config.onReportLogs || ((_logs) => {})
this.loadNodesPromise = this.config.experimental ? this._loadNodes(this.config) : null
this.authLimiter = pLimit(1)
this.logsLastReportedAt = null
}

/**
Expand Down Expand Up @@ -469,8 +470,15 @@ export class Saturn {
reportLogs (log) {
this.logs.push(log)
if (!this.reportingLogs) return
this.reportLogsTimeout && clearTimeout(this.reportLogsTimeout)
this.reportLogsTimeout = setTimeout(this._reportLogs.bind(this), 3_000)
clearTimeout(this.reportLogsTimeout)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
clearTimeout(this.reportLogsTimeout)
this.reportLogsTimeout && clearTimeout(this.reportLogsTimeout)

this.reportLogsTimeout may be null

if (
!this.logsLastReportedAt ||
this.logsLastReportedAt.getTime() < new Date().getTime() - 10_000
) {
this._reportLogs()
} else {
this.reportLogsTimeout = setTimeout(this._reportLogs.bind(this), 3_000)
}
}

async _reportLogs () {
Expand All @@ -490,6 +498,7 @@ export class Saturn {
body: JSON.stringify({ bandwidthLogs, logSender: this.config.logSender })
}
)
this.logsLastReportedAt = new Date()
this.onReportLogs(bandwidthLogs)
} catch (e) {
console.log(e)
Expand Down