Skip to content

Add Eq and CPS fromKillSignal #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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