MCPcopy
hub / github.com/apify/crawlee / waitForCondition

Function waitForCondition

test/utils/psTree.test.ts:12–26  ·  view source on GitHub ↗
(
    pid: number,
    condition: (children: any[]) => boolean,
    maxWaitMs = 3000,
)

Source from the content-addressed store, hash-verified

10
11// Helper to poll for a condition on process tree
12async function waitForCondition(
13 pid: number,
14 condition: (children: any[]) => boolean,
15 maxWaitMs = 3000,
16): Promise<any[]> {
17 const startTime = Date.now();
18 while (Date.now() - startTime < maxWaitMs) {
19 const children = await psTree(pid);
20 if (condition(children)) {
21 return children;
22 }
23 await new Promise((resolve) => setTimeout(resolve, 100));
24 }
25 return psTree(pid); // Final attempt
26}
27
28describe('psTree()', () => {
29 test('Spawn a Parent process which has Ten Child Processes', async () => {

Callers 1

psTree.test.tsFile · 0.85

Calls 1

psTreeFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…