Files
mtdb_movie/common/resources/client/ui/toast/toast-timer.ts
maher 703f50a09d
Some checks failed
Build / run (push) Has been cancelled
first commit
2025-10-29 11:42:25 +01:00

26 lines
535 B
TypeScript
Executable File

export class ToastTimer {
private timerId?: ReturnType<typeof setTimeout>;
private createdAt: number = 0;
constructor(private callback: () => void, private remaining: number) {
this.resume();
}
pause() {
clearTimeout(this.timerId);
this.remaining -= Date.now() - this.createdAt;
}
resume() {
this.createdAt = Date.now();
if (this.timerId) {
clearTimeout(this.timerId);
}
this.timerId = setTimeout(this.callback, this.remaining);
}
clear() {
clearTimeout(this.timerId);
}
}