Molodetz blogrol volgens DPP-template

This commit is contained in:
2026-10-05 09:36:20 +02:00
commit f290a4c766
277 changed files with 15758 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
// retoor <retoor@molodetz.nl>
export class Poller {
constructor(fn, intervalMs, { immediate = false, pauseHidden = true } = {}) {
this.fn = fn;
this.intervalMs = intervalMs;
this.immediate = immediate;
this.pauseHidden = pauseHidden;
this.timer = null;
this.busy = false;
}
start() {
if (this.timer) {
return this;
}
if (this.immediate) {
this.tick();
}
this.timer = setInterval(() => this.tick(), this.intervalMs);
return this;
}
stop() {
clearInterval(this.timer);
this.timer = null;
}
async tick() {
if (this.busy || (this.pauseHidden && document.hidden)) {
return;
}
this.busy = true;
try {
await this.fn();
} catch (error) {
console.debug("poller tick failed", error);
} finally {
this.busy = false;
}
}
}