MCPcopy Index your code
hub / github.com/anomalyco/opencode / killTree

Function killTree

packages/core/src/shell.ts:31–60  ·  view source on GitHub ↗
(proc: ChildProcess, opts?: { exited?: () => boolean })

Source from the content-addressed store, hash-verified

29}
30
31export async function killTree(proc: ChildProcess, opts?: { exited?: () => boolean }): Promise<void> {
32 const pid = proc.pid
33 if (!pid || opts?.exited?.()) return
34
35 if (process.platform === "win32") {
36 await new Promise<void>((resolve) => {
37 const killer = spawn("taskkill", ["/pid", String(pid), "/f", "/t"], {
38 stdio: "ignore",
39 windowsHide: true,
40 })
41 killer.once("exit", () => resolve())
42 killer.once("error", () => resolve())
43 })
44 return
45 }
46
47 try {
48 process.kill(-pid, "SIGTERM")
49 await sleep(SIGKILL_TIMEOUT_MS)
50 if (!opts?.exited?.()) {
51 process.kill(-pid, "SIGKILL")
52 }
53 } catch {
54 proc.kill("SIGTERM")
55 await sleep(SIGKILL_TIMEOUT_MS)
56 if (!opts?.exited?.()) {
57 proc.kill("SIGKILL")
58 }
59 }
60}
61
62function stat(file: string) {
63 return statSync(file, { throwIfNoEntry: false }) ?? undefined

Callers

nothing calls this directly

Calls 3

resolveFunction · 0.70
spawnFunction · 0.50
sleepFunction · 0.50

Tested by

no test coverage detected