MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / retryWithFixedDelay

Function retryWithFixedDelay

ai/ai.ts:1031–1051  ·  view source on GitHub ↗
(
  operation: () => Promise<T>,
  maxRetries: number = 2,
  delayMs: number = 1000,
  token?: AbortToken,
)

Source from the content-addressed store, hash-verified

1029
1030const retryWithFixedDelay = async <T>(
1031 operation: () => Promise<T>,
1032 maxRetries: number = 2,
1033 delayMs: number = 1000,
1034 token?: AbortToken,
1035): Promise<T> => {
1036 let lastError: any;
1037 for (let i = 0; i < maxRetries; i++) {
1038 token?.throwIfAborted();
1039 try {
1040 return await operation();
1041 } catch (error: any) {
1042 lastError = error;
1043 if (token?.aborted) throw error;
1044 if (!isRetryableError(error)) throw error;
1045 if (i === maxRetries - 1) break;
1046 await sleep(delayMs, token);
1047 }
1048 }
1049 throw lastError;
1050};
1051
1052const isRetryableError = (error: any): boolean => {
1053 if (!error) return false;
1054 if (error.name === "AbortError") return false;

Callers 1

pollTaskFunction · 0.85

Calls 3

isRetryableErrorFunction · 0.85
sleepFunction · 0.70
throwIfAbortedMethod · 0.65

Tested by

no test coverage detected