MCPcopy Create free account
hub / github.com/deepnote/vscode-deepnote / waitForCondition

Function waitForCondition

src/platform/common/utils/async.ts:19–43  ·  view source on GitHub ↗
(
    condition: () => Promise<boolean>,
    timeout: number,
    interval: number
)

Source from the content-addressed store, hash-verified

17}
18
19export async function waitForCondition(
20 condition: () => Promise<boolean>,
21 timeout: number,
22 interval: number
23): Promise<boolean> {
24 // Set a timer that will resolve with null
25 return new Promise<boolean>((resolve) => {
26 let finish: (result: boolean) => void;
27 const timer = setTimeout(() => finish(false), timeout);
28 const intervalId = setInterval(() => {
29 condition()
30 .then((r) => {
31 if (r) {
32 finish(true);
33 }
34 })
35 .catch((_e) => finish(false));
36 }, interval);
37 finish = (result: boolean) => {
38 clearTimeout(timer);
39 clearInterval(intervalId);
40 resolve(result);
41 };
42 });
43}
44
45export function raceTimeout<T>(timeout: number, ...promises: Promise<T>[]): Promise<T | undefined>;
46export function raceTimeout<T>(timeout: number, defaultValue: T, ...promises: Promise<T>[]): Promise<T>;

Callers 3

switchKernelMethod · 0.90
asyncAssertReporterStateFunction · 0.90

Calls 1

resolveFunction · 0.50

Tested by 1

asyncAssertReporterStateFunction · 0.72