mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-04-21 15:53:50 +02:00
feat: mutual friend graph (#1491)
This commit is contained in:
24
src/shared/utils/retry.js
Normal file
24
src/shared/utils/retry.js
Normal file
@@ -0,0 +1,24 @@
|
||||
export async function executeWithBackoff(fn, options = {}) {
|
||||
const {
|
||||
maxRetries = 5,
|
||||
baseDelay = 1000,
|
||||
shouldRetry = () => true
|
||||
} = options;
|
||||
|
||||
async function attempt(remaining) {
|
||||
try {
|
||||
return await fn();
|
||||
} catch (err) {
|
||||
if (remaining <= 0 || !shouldRetry(err)) {
|
||||
throw err;
|
||||
}
|
||||
const delay =
|
||||
baseDelay *
|
||||
Math.pow(2, (options.maxRetries || maxRetries) - remaining);
|
||||
await new Promise((resolve) => setTimeout(resolve, delay));
|
||||
return attempt(remaining - 1);
|
||||
}
|
||||
}
|
||||
|
||||
return attempt(maxRetries);
|
||||
}
|
||||
Reference in New Issue
Block a user