MCPcopy Create free account
hub / github.com/callumalpass/tasknotes / executeWithRetry

Method executeWithRetry

src/utils/safeAsync.ts:72–121  ·  view source on GitHub ↗

* Execute an async operation with retry logic

(
		operation: () => Promise<T>,
		options: {
			maxRetries?: number;
			retryDelay?: number;
			errorMessage?: string;
			showNotice?: boolean;
			noticeHandler?: SafeAsyncNoticeHandler;
		} = {}
	)

Source from the content-addressed store, hash-verified

70 * Execute an async operation with retry logic
71 */
72 static async executeWithRetry<T>(
73 operation: () => Promise<T>,
74 options: {
75 maxRetries?: number;
76 retryDelay?: number;
77 errorMessage?: string;
78 showNotice?: boolean;
79 noticeHandler?: SafeAsyncNoticeHandler;
80 } = {}
81 ): Promise<T | undefined> {
82 const {
83 maxRetries = 3,
84 retryDelay = 1000,
85 errorMessage = "Operation failed",
86 showNotice = true,
87 noticeHandler,
88 } = options;
89
90 let lastError: Error;
91
92 for (let attempt = 0; attempt <= maxRetries; attempt++) {
93 try {
94 return await operation();
95 } catch (error) {
96 lastError = error instanceof Error ? error : new Error(String(error));
97
98 if (attempt < maxRetries) {
99 await new Promise((resolve) => window.setTimeout(resolve, retryDelay));
100 continue;
101 }
102
103 // Final attempt failed
104 tasknotesLogger.error(`${errorMessage} after ${maxRetries + 1} attempts:`, {
105 category: "provider",
106 operation: "execute-with-retry",
107 details: { attempts: maxRetries + 1 },
108 error: lastError,
109 });
110
111 if (showNotice) {
112 notifyIfRequested(`${errorMessage}: ${lastError.message}`, {
113 showNotice,
114 noticeHandler,
115 });
116 }
117
118 return undefined;
119 }
120 }
121 }
122
123 /**
124 * Validate input before executing operation

Callers

nothing calls this directly

Calls 3

notifyIfRequestedFunction · 0.85
errorMethod · 0.80
setTimeoutMethod · 0.65

Tested by

no test coverage detected