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

Function waitFor

src/shared/utils/promises.ts:3–16  ·  view source on GitHub ↗
(action: () => T | Promise<T>, checkEveryMilliseconds = 50, tryForMilliseconds = 15000, token?: { isCancellationRequested: boolean })

Source from the content-addressed store, hash-verified

1export const resolvedPromise = Promise.resolve();
2
3export async function waitFor<T>(action: () => T | Promise<T>, checkEveryMilliseconds = 50, tryForMilliseconds = 15000, token?: { isCancellationRequested: boolean }): Promise<T | undefined> {
4 let timeRemaining = tryForMilliseconds;
5 while (timeRemaining > 0 && !(token?.isCancellationRequested)) {
6 try {
7 const res = await action();
8 if (res)
9 return res;
10 } catch {
11 // Just try again if it throws.
12 }
13 await new Promise((resolve) => setTimeout(resolve, checkEveryMilliseconds).unref());
14 timeRemaining -= checkEveryMilliseconds;
15 }
16}

Callers 15

helpers.tsFile · 0.90
getCodeActionsFunction · 0.90
waitForResultFunction · 0.90
waitForEditorChangeFunction · 0.90
dart_test.test.tsFile · 0.90
add.test.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected