Skip to content

Commit 2a1f094

Browse files
Profpatschkritzcreek
authored andcommitted
Make kill return Unit instead of Boolean
The underlying implementation in `node/lib/internal/child_process.js` does return a boolean value, but this value is devoid of any semantic content. Shortened it does: ``` if childProcessHandle { res = child.kill(signal) if (res === 0) { child.killed = true; return true; else { throwError() } } else { return false; } ``` which means the returned boolean depends on whether the subprocess still exists and whether the signal was successfully sent (apparently the original author thought that sending a signal will always kill the process). The return value isn’t even mentioned in the documentation, so it must be a historical artifact kept around for backward compatibility.
1 parent 32f1a0c commit 2a1f094

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/Node/ChildProcess.purs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ type ChildProcessRec =
8383
, stderr :: Nullable (Readable ())
8484
, pid :: Pid
8585
, connected :: Boolean
86-
, kill :: String -> Boolean
86+
, kill :: String -> Unit
8787
, send :: forall r. Fn2 { | r} Handle Boolean
8888
, disconnect :: Effect Unit
8989
}
@@ -125,10 +125,15 @@ send msg handle (ChildProcess cp) = mkEffect \_ -> runFn2 cp.send msg handle
125125
disconnect :: ChildProcess -> Effect Unit
126126
disconnect = _.disconnect <<< runChildProcess
127127

128-
-- | Send a signal to a child process. It's an unfortunate historical decision
129-
-- | that this function is called "kill", as sending a signal to a child
130-
-- | process won't necessarily kill it.
131-
kill :: Signal -> ChildProcess -> Effect Boolean
128+
-- | Send a signal to a child process. In the same way as the
129+
-- | [unix kill(2) system call](https://linux.die.net/man/2/kill),
130+
-- | sending a signal to a child process won't necessarily kill it.
131+
-- |
132+
-- | The resulting effects of this function depend on the process
133+
-- | and the signal and can vary from system to system.
134+
-- | The child process might emit an "error" event if the signal
135+
-- | could not be delivered.
136+
kill :: Signal -> ChildProcess -> Effect Unit
132137
kill sig (ChildProcess cp) = mkEffect \_ -> cp.kill (Signal.toString sig)
133138

134139
mkEffect :: forall a. (Unit -> a) -> Effect a

0 commit comments

Comments
 (0)