Skip to content

Commit

Permalink
fix too many updates
Browse files Browse the repository at this point in the history
  • Loading branch information
spookyuser committed Jan 5, 2024
1 parent 7a80cbe commit a7c5549
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
coverage
dist
node_modules
.vscode
7 changes: 5 additions & 2 deletions source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ export class ConsoleProgressBar {
throw new TypeError("currentValue must be a number")
}

if (performance.now() - this.lastUpdate < this.updateInterval) {
const now = performance.now()
if (now - this.lastUpdate < this.updateInterval) {
return
}

Expand All @@ -60,8 +61,10 @@ export class ConsoleProgressBar {
this.generateProgressBarString(
this.getPercentage(),
this.eta.estimate() * 1000
) // We need ms so
)
)

this.lastUpdate = now // Update the lastUpdate time
}

private getPercentage() {
Expand Down

0 comments on commit a7c5549

Please sign in to comment.