streamana/site/update-limiter.js

16 lines
318 B
JavaScript
Raw Normal View History

2021-07-09 03:55:27 +08:00
export class UpdateLimiter {
constructor(nps) {
this.threshold = nps ? 1000/nps : 0;
2021-07-09 03:55:27 +08:00
this.last = 0;
}
check() {
const now = Date.now();
if ((now - this.last) >= this.threshold) {
this.last = now;
return true;
}
return false;
}
}