1
0
mirror of https://github.com/misskey-dev/misskey.git synced 2026-05-22 23:24:10 +02:00
This commit is contained in:
syuilo
2026-04-19 20:15:51 +09:00
parent 3811de2283
commit e402057d3b
6 changed files with 50 additions and 42 deletions

View File

@@ -660,3 +660,33 @@ export class RecyvlingTextGrid {
export function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}
export class Timer {
private timeoutIds: number[] = [];
private intervalIds: number[] = [];
public setTimeout(callback: () => void, ms: number) {
const id = window.setTimeout(() => {
this.timeoutIds = this.timeoutIds.filter(i => i !== id);
callback();
}, ms);
this.timeoutIds.push(id);
}
public setInterval(callback: () => void, ms: number) {
const id = window.setInterval(callback, ms);
this.intervalIds.push(id);
}
public dispose() {
for (const id of this.timeoutIds) {
window.clearTimeout(id);
}
this.timeoutIds = [];
for (const id of this.intervalIds) {
window.clearInterval(id);
}
this.intervalIds = [];
}
}