Skip to content

Commit

Permalink
refactor: only pass watchdog pid
Browse files Browse the repository at this point in the history
  • Loading branch information
frattaro committed Aug 7, 2024
1 parent d0273cc commit d750ebd
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Serializable,
spawn as nodeSpawn,
SpawnOptions,
ChildProcess,
} from 'child_process'
import crossSpawn from 'cross-spawn'
import { onExit } from 'signal-exit'
Expand Down Expand Up @@ -38,8 +39,8 @@ export type Cleanup = (
code: number | null,
signal: null | NodeJS.Signals,
processInfo: {
watchdog: ChildProcess
}
watchdogPid: ChildProcess['pid']
},
) =>
| void
| undefined
Expand Down Expand Up @@ -162,7 +163,7 @@ export function foregroundChild(
const removeOnExit = onExit(childHangup)

proxySignals(child)
watchdog(child)
const dog = watchdog(child)

let done = false
child.on('close', async (code, signal) => {
Expand All @@ -171,7 +172,7 @@ export function foregroundChild(
/* c8 ignore stop */
done = true
const result = cleanup(code, signal, {
watchdog: dog,
watchdogPid: dog.pid,
})
const res = isPromise(result) ? await result : result
removeOnExit()
Expand Down

0 comments on commit d750ebd

Please sign in to comment.