-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move fetch retry client to core and add better timeout and listener c…
…leanup
- Loading branch information
1 parent
808df13
commit ff2292c
Showing
5 changed files
with
91 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,31 @@ | ||
export const sleep = (ms: number, { enabled = true }: { enabled?: boolean } = {}): Promise<void> => | ||
enabled ? new Promise((resolve) => setTimeout(resolve, ms)) : Promise.resolve(); | ||
|
||
export type CancellableSleep = { | ||
promise: Promise<void>; | ||
cancel: () => void; | ||
}; | ||
|
||
export const sleepWithCancel = ( | ||
ms: number, | ||
{ enabled = true }: { enabled?: boolean } = {}, | ||
): CancellableSleep => { | ||
if (!enabled) { | ||
return { | ||
promise: Promise.resolve(), | ||
cancel: () => {}, // No-op for disabled sleep | ||
}; | ||
} | ||
|
||
let timeoutId: ReturnType<typeof setTimeout>; | ||
const promise = new Promise<void>((resolve) => { | ||
timeoutId = setTimeout(resolve, ms); | ||
}); | ||
|
||
return { | ||
promise, | ||
cancel: () => { | ||
clearTimeout(timeoutId); | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters