MCPcopy Create free account
hub / github.com/Dart-Code/Dart-Code / withTimeout

Function withTimeout

src/shared/utils.ts:272–292  ·  view source on GitHub ↗
(promise: Thenable<T>, message: string | (() => string), seconds = 360)

Source from the content-addressed store, hash-verified

270}
271
272export async function withTimeout<T>(promise: Thenable<T>, message: string | (() => string), seconds = 360): Promise<T> {
273 return new Promise<T>((resolve, reject) => {
274 // Set a timeout to reject the promise after the timeout period.
275 const timeoutTimer = setTimeout(() => {
276 const msg = typeof message === "string" ? message : message();
277 reject(new Error(`${msg} within ${seconds}s`));
278 }, seconds * 1000);
279
280 // When the main promise completes (or rejects), cancel the timeout and return its result.
281 promise.then(
282 (result) => {
283 clearTimeout(timeoutTimer);
284 resolve(result);
285 },
286 (e) => {
287 clearTimeout(timeoutTimer);
288 reject(e);
289 },
290 );
291 });
292}
293
294/**
295 * Returns a "fixed" toolEnv to work around a Copilot env var mutation issue.

Callers 8

assertOutputContainsMethod · 0.90
closeAllOpenFilesFunction · 0.90
waitForNextAnalysisFunction · 0.90
createDebugClientFunction · 0.90
activateFunction · 0.90
startPingMethod · 0.90
disposeAllAsyncFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected