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 {
|
||||
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();
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user