Update the safeSetTimeout function to pass the test

This commit is contained in:
MSomnium Studios 2025-10-06 10:31:08 -04:00 committed by GitHub
parent 3bdd2546e4
commit 5d391fa4e0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -95,19 +95,17 @@ export function createURL(endpoint: string, searchParams = {}): string {
export function setSafeTimeout(callback: () => void, delay: number): number {
const MAX_DELAY = 86_400_000;
let remaining = delay;
let timerId: number;
function scheduleNext() {
function scheduleNext(): number {
if (remaining <= MAX_DELAY) {
timerId = window.setTimeout(callback, remaining);
return window.setTimeout(callback, remaining);
} else {
timerId = window.setTimeout(() => {
return window.setTimeout(() => {
remaining -= MAX_DELAY;
scheduleNext();
}, MAX_DELAY);
}
}
scheduleNext();
return timerId;
return scheduleNext();
}