Skip to content

Commit

Permalink
Add Eq and CPS fromKillSignal (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanMartinez authored Jul 26, 2023
1 parent e907271 commit 4d27b66
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ Breaking changes:
- `kill'`'s signal arg

New features:
- Added `fromKillSignal` (#51 by @JordanMartinez)
- Added `fromKillSignal`, `fromKillSignal'` (#51, #59 by @JordanMartinez)
- Added `pidExists` (#53 by @JordanMartinez)
- Export `toUnsafeChildProcess` (#55 by @JordanMartinez)
- Added `stdio` (#55 by @JordanMartinez)
- Added `Show` instance to `Shell` & `KillSignal` (#58 by @JordanMartinez)
- Added `Eq` and `Show` instance to `Shell` & `KillSignal` (#58, #59 by @JordanMartinez)

Other improvements:
- Fix regression: add `ref`/`unref` APIs that were dropped in `v10.0.0` (#50 by @JordanMartinez)
Expand Down
19 changes: 17 additions & 2 deletions src/Node/ChildProcess/Types.purs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module Node.ChildProcess.Types
, intSignal
, stringSignal
, fromKillSignal
, fromKillSignal'
, Shell
, enableShell
, customShell
Expand Down Expand Up @@ -72,6 +73,17 @@ defaultStdIO = unsafeCoerce (null :: Nullable String)

foreign import data KillSignal :: Type

instance Eq KillSignal where
eq a b = a # fromKillSignal'
( \i -> b # fromKillSignal'
(\b' -> i == b')
(const false)
)
( \s -> b # fromKillSignal'
(const false)
(\b' -> s == b')
)

instance Show KillSignal where
show = showKillSignal

Expand All @@ -84,9 +96,12 @@ stringSignal :: String -> KillSignal
stringSignal = unsafeCoerce

fromKillSignal :: KillSignal -> Either Int String
fromKillSignal sig = runFn3 fromKillSignalImpl Left Right sig
fromKillSignal sig = fromKillSignal' Left Right sig

fromKillSignal' :: forall r. (Int -> r) -> (String -> r) -> KillSignal -> r
fromKillSignal' fromInt fromStr sig = runFn3 fromKillSignalImpl fromInt fromStr sig

foreign import fromKillSignalImpl :: Fn3 (forall l r. l -> Either l r) (forall l r. r -> Either l r) (KillSignal) (Either Int String)
foreign import fromKillSignalImpl :: forall r. Fn3 (Int -> r) (String -> r) (KillSignal) r

foreign import data Shell :: Type

Expand Down

0 comments on commit 4d27b66

Please sign in to comment.