MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / runChild

Function runChild

__tests__/liveness-watchdog.test.ts:57–82  ·  view source on GitHub ↗
(
    env: Record<string, string>,
    body: string,
    hardTimeoutMs: number,
    progressPaths?: string[]
  )

Source from the content-addressed store, hash-verified

55 });
56
57 function runChild(
58 env: Record<string, string>,
59 body: string,
60 hardTimeoutMs: number,
61 progressPaths?: string[]
62 ): Promise<{ code: number | null; signal: NodeJS.Signals | 'TIMEOUT' | null }> {
63 const src = `
64 const { installMainThreadWatchdog } = require(${JSON.stringify(MODULE)});
65 installMainThreadWatchdog(${progressPaths ? JSON.stringify({ progressPaths }) : ''});
66 ${body}
67 `;
68 const child = spawn(process.execPath, ['-e', src], {
69 env: { ...process.env, ...env },
70 stdio: ['ignore', 'ignore', 'ignore'],
71 });
72 return new Promise((resolve) => {
73 const timer = setTimeout(() => {
74 child.kill('SIGKILL');
75 resolve({ code: null, signal: 'TIMEOUT' });
76 }, hardTimeoutMs);
77 child.on('exit', (code, signal) => {
78 clearTimeout(timer);
79 resolve({ code, signal });
80 });
81 });
82 }
83
84 // Assert the watchdog terminated the process. POSIX surfaces the external
85 // SIGKILL as signal 'SIGKILL'; Windows has no real signals, so the watchdog's

Callers 1

Calls 2

onMethod · 0.65
resolveFunction · 0.50

Tested by

no test coverage detected