@@ -26,9 +26,14 @@ module Node.ChildProcess
26
26
, stderr
27
27
, pid
28
28
, connected
29
+ , disconnect
30
+ , exitCode
29
31
, kill
32
+ , kill'
33
+ , killSignal
34
+ , killed
35
+ , signalCode
30
36
, send
31
- , disconnect
32
37
, Error
33
38
, toStandardError
34
39
, Exit (..)
@@ -61,7 +66,7 @@ import Data.Posix.Signal (Signal)
61
66
import Data.Posix.Signal as Signal
62
67
import Effect (Effect )
63
68
import Effect.Exception as Exception
64
- import Effect.Uncurried (EffectFn2 , mkEffectFn1 , mkEffectFn2 )
69
+ import Effect.Uncurried (EffectFn1 , EffectFn2 , mkEffectFn1 , mkEffectFn2 , runEffectFn1 , runEffectFn2 )
65
70
import Foreign (Foreign )
66
71
import Foreign.Object (Object )
67
72
import Node.Buffer (Buffer )
@@ -152,13 +157,22 @@ foreign import unsafeFromNullable :: forall a. String -> Nullable a -> a
152
157
153
158
-- | The process ID of a child process. Note that if the process has already
154
159
-- | 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 )
157
164
158
165
-- | Indicates whether it is still possible to send and receive
159
166
-- | messages from the child process.
160
167
connected :: 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 )
162
176
163
177
-- | Send messages to the (`nodejs`) child process.
164
178
-- |
@@ -174,7 +188,19 @@ send msg handle (ChildProcess cp) = mkEffect \_ -> runFn2 cp.send msg handle
174
188
175
189
-- | Closes the IPC channel between parent and child.
176
190
disconnect :: 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 )
178
204
179
205
-- | Send a signal to a child process. In the same way as the
180
206
-- | [unix kill(2) system call](https://linux.die.net/man/2/kill),
@@ -184,8 +210,22 @@ disconnect = _.disconnect <<< runChildProcess
184
210
-- | and the signal. They can vary from system to system.
185
211
-- | The child process might emit an `"error"` event if the signal
186
212
-- | 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
189
229
190
230
mkEffect :: forall a . (Unit -> a ) -> Effect a
191
231
mkEffect = unsafeCoerce
0 commit comments