Update the safeSetTimeout function to pass the test
This commit is contained in:
parent
3bdd2546e4
commit
5d391fa4e0
@ -95,19 +95,17 @@ export function createURL(endpoint: string, searchParams = {}): string {
|
|||||||
export function setSafeTimeout(callback: () => void, delay: number): number {
|
export function setSafeTimeout(callback: () => void, delay: number): number {
|
||||||
const MAX_DELAY = 86_400_000;
|
const MAX_DELAY = 86_400_000;
|
||||||
let remaining = delay;
|
let remaining = delay;
|
||||||
let timerId: number;
|
|
||||||
|
|
||||||
function scheduleNext() {
|
function scheduleNext(): number {
|
||||||
if (remaining <= MAX_DELAY) {
|
if (remaining <= MAX_DELAY) {
|
||||||
timerId = window.setTimeout(callback, remaining);
|
return window.setTimeout(callback, remaining);
|
||||||
} else {
|
} else {
|
||||||
timerId = window.setTimeout(() => {
|
return window.setTimeout(() => {
|
||||||
remaining -= MAX_DELAY;
|
remaining -= MAX_DELAY;
|
||||||
scheduleNext();
|
scheduleNext();
|
||||||
}, MAX_DELAY);
|
}, MAX_DELAY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
scheduleNext();
|
return scheduleNext();
|
||||||
return timerId;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user