Skip to content

Commit

Permalink
Added sendExitSignal
Browse files Browse the repository at this point in the history
  • Loading branch information
srstrong authored and nwolverson committed Oct 12, 2021
1 parent 2975184 commit 913661b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Erl/Process.purs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module Erl.Process
, receiveWithTimeout
, spawn
, spawnLink
, sendExitSignal
, class HasProcess
, class ReceivesMessage
, class HasSelf
Expand All @@ -27,8 +28,10 @@ import Data.Time.Duration (Milliseconds(..))
import Effect (Effect)
import Effect.Class (class MonadEffect, liftEffect)
import Erl.Process.Raw (ExitReason(..), ExitMsg(..)) as RawExport
import Erl.Process.Raw (ExitReason)
import Erl.Process.Raw (ExitReason, getPid)
import Erl.Process.Raw as Raw
import Foreign (Foreign)
import Unsafe.Coerce (unsafeCoerce)

newtype Process (a :: Type)
= Process Raw.Pid
Expand Down Expand Up @@ -96,6 +99,10 @@ spawn (ProcessM e) = Process <$> Raw.spawn e
spawnLink :: forall a. ProcessM a Unit -> Effect (Process a)
spawnLink (ProcessM e) = Process <$> Raw.spawnLink e

sendExitSignal :: forall a. Foreign -> Process a -> Effect Unit
sendExitSignal reason (Process pid) = do
Raw.sendExitSignal reason pid

class HasProcess b a where
getProcess :: a -> Process b

Expand Down
3 changes: 3 additions & 0 deletions src/Erl/Process/Raw.erl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
self/0,
setProcessFlagTrapExit/1,
exit/1,
sendExitSignal/2,
unlink/1
]).

Expand Down Expand Up @@ -73,4 +74,6 @@ end.

exit(Term) -> fun () -> erlang:exit(Term) end.

sendExitSignal(Term, Pid) -> fun () -> erlang:exit(Pid, Term) end.

unlink(Pid) -> fun() -> erlang:unlink(Pid) end.
3 changes: 3 additions & 0 deletions src/Erl/Process/Raw.purs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module Erl.Process.Raw
, class HasPid
, getPid
, exit
, sendExitSignal
, unlink
) where

Expand Down Expand Up @@ -67,6 +68,8 @@ foreign import receiveWithTrapAndTimeout_ :: forall a. Int -> a -> Effect (Eithe

foreign import setProcessFlagTrapExit :: Boolean -> Effect Boolean

foreign import sendExitSignal :: Foreign -> Pid -> Effect Unit

foreign import exit :: Foreign -> Effect Unit

foreign import unlink :: Pid -> Effect Unit

0 comments on commit 913661b

Please sign in to comment.