@@ -26,9 +26,14 @@ module Node.ChildProcess
2626 , stderr
2727 , pid
2828 , connected
29+ , disconnect
30+ , exitCode
2931 , kill
32+ , kill'
33+ , killSignal
34+ , killed
35+ , signalCode
3036 , send
31- , disconnect
3237 , Error
3338 , toStandardError
3439 , Exit (..)
@@ -61,7 +66,7 @@ import Data.Posix.Signal (Signal)
6166import Data.Posix.Signal as Signal
6267import Effect (Effect )
6368import Effect.Exception as Exception
64- import Effect.Uncurried (EffectFn2 , mkEffectFn1 , mkEffectFn2 )
69+ import Effect.Uncurried (EffectFn1 , EffectFn2 , mkEffectFn1 , mkEffectFn2 , runEffectFn1 , runEffectFn2 )
6570import Foreign (Foreign )
6671import Foreign.Object (Object )
6772import Node.Buffer (Buffer )
@@ -152,13 +157,22 @@ foreign import unsafeFromNullable :: forall a. String -> Nullable a -> a
152157
153158-- | The process ID of a child process. Note that if the process has already
154159-- | exited, another process may have taken the same ID, so be careful!
155- pid :: ChildProcess -> Pid
156- pid = _.pid <<< runChildProcess
160+ pid :: ChildProcess -> Effect (Maybe Pid )
161+ pid cp = map toMaybe $ runEffectFn1 pidImpl cp
162+
163+ foreign import pidImpl :: EffectFn1 (ChildProcess ) (Nullable Pid )
157164
158165-- | Indicates whether it is still possible to send and receive
159166-- | messages from the child process.
160167connected :: ChildProcess -> Effect Boolean
161- connected (ChildProcess cp) = mkEffect \_ -> cp.connected
168+ connected cp = runEffectFn1 connectedImpl cp
169+
170+ foreign import connectedImpl :: EffectFn1 (ChildProcess ) (Boolean )
171+
172+ exitCode :: ChildProcess -> Effect (Maybe Int )
173+ exitCode cp = map toMaybe $ runEffectFn1 exitCodeImpl cp
174+
175+ foreign import exitCodeImpl :: EffectFn1 (ChildProcess ) (Nullable Int )
162176
163177-- | Send messages to the (`nodejs`) child process.
164178-- |
@@ -174,7 +188,19 @@ send msg handle (ChildProcess cp) = mkEffect \_ -> runFn2 cp.send msg handle
174188
175189-- | Closes the IPC channel between parent and child.
176190disconnect :: ChildProcess -> Effect Unit
177- disconnect = _.disconnect <<< runChildProcess
191+ disconnect cp = runEffectFn1 disconnectImpl cp
192+
193+ foreign import disconnectImpl :: EffectFn1 (ChildProcess ) (Unit )
194+
195+ kill :: ChildProcess -> Effect Boolean
196+ kill cp = runEffectFn1 killImpl cp
197+
198+ foreign import killImpl :: EffectFn1 (ChildProcess ) (Boolean )
199+
200+ kill' :: String -> ChildProcess -> Effect Boolean
201+ kill' sig cp = runEffectFn2 killStrImpl cp sig
202+
203+ foreign import killStrImpl :: EffectFn2 (ChildProcess ) (String ) (Boolean )
178204
179205-- | Send a signal to a child process. In the same way as the
180206-- | [unix kill(2) system call](https://linux.die.net/man/2/kill),
@@ -184,8 +210,22 @@ disconnect = _.disconnect <<< runChildProcess
184210-- | and the signal. They can vary from system to system.
185211-- | The child process might emit an `"error"` event if the signal
186212-- | could not be delivered.
187- kill :: Signal -> ChildProcess -> Effect Unit
188- kill sig (ChildProcess cp) = mkEffect \_ -> cp.kill (Signal .toString sig)
213+ killSignal :: Signal -> ChildProcess -> Effect Boolean
214+ killSignal sig cp = kill' (Signal .toString sig) cp
215+
216+ killed :: ChildProcess -> Effect Boolean
217+ killed cp = runEffectFn1 killedImpl cp
218+
219+ signalCode :: ChildProcess -> Effect (Maybe String )
220+ signalCode cp = map toMaybe $ runEffectFn1 signalCodeImpl cp
221+
222+ foreign import signalCodeImpl :: EffectFn1 (ChildProcess ) (Nullable String )
223+
224+ foreign import killedImpl :: EffectFn1 (ChildProcess ) (Boolean )
225+
226+ foreign import spawnArgs :: ChildProcess -> Array String
227+
228+ foreign import spawnFile :: ChildProcess -> String
189229
190230mkEffect :: forall a . (Unit -> a ) -> Effect a
191231mkEffect = unsafeCoerce
0 commit comments