Migrate to private class properties/methods

This commit is contained in:
Jamie Kyle 2025-01-14 11:11:52 -08:00 committed by GitHub
commit aa9f53df57
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
100 changed files with 3795 additions and 3944 deletions

View file

@ -9,35 +9,34 @@ export type Timeout = {
};
export class Timers {
private counter = 0;
private readonly timers = new Map<number, NodeJS.Timeout>();
#counter = 0;
readonly #timers = new Map<number, NodeJS.Timeout>();
public setTimeout(callback: () => void, delay: number): Timeout {
let id: number;
do {
id = this.counter;
id = this.#counter;
// eslint-disable-next-line no-bitwise
this.counter = (this.counter + 1) >>> 0;
} while (this.timers.has(id));
this.#counter = (this.#counter + 1) >>> 0;
} while (this.#timers.has(id));
const timer = setTimeout(() => {
this.timers.delete(id);
this.#timers.delete(id);
callback();
}, delay);
this.timers.set(id, timer);
this.#timers.set(id, timer);
return { id } as unknown as Timeout;
}
public clearTimeout({ id }: Timeout): ReturnType<typeof clearTimeout> {
const timer = this.timers.get(id);
const timer = this.#timers.get(id);
if (timer === undefined) {
return;
}
this.timers.delete(id);
this.#timers.delete(id);
return clearTimeout(timer);
}
}