MCPcopy Create free account
hub / github.com/angular/angular / waitFor

Function waitFor

ngp-vscode-ng-language-service/e2e/src/utils.ts:14–30  ·  view source on GitHub ↗
(
  action: () => PromiseLike<T> | T,
  isValid: (result: T) => boolean,
  options: WaitForOptions = {},
)

Source from the content-addressed store, hash-verified

12}
13
14export async function waitFor<T>(
15 action: () => PromiseLike<T> | T,
16 isValid: (result: T) => boolean,
17 options: WaitForOptions = {},
18): Promise<T> {
19 const timeout = options.timeout ?? 5000;
20 const interval = options.interval ?? 100;
21 const startTime = Date.now();
22 while (Date.now() - startTime < timeout) {
23 const result = await action();
24 if (isValid(result)) {
25 return result;
26 }
27 await new Promise((resolve) => setTimeout(resolve, interval));
28 }
29 throw new Error(`Timed out waiting for condition after ${timeout}ms`);
30}

Callers 7

runFunction · 0.90
runFunction · 0.90
runSingleDiagnosticTestFunction · 0.90
runFunction · 0.90
runFunction · 0.90

Calls 3

setTimeoutFunction · 0.85
nowMethod · 0.80
isValidFunction · 0.50

Tested by

no test coverage detected