diff --git a/src/Erl/Process.purs b/src/Erl/Process.purs index b26f123..846abbc 100644 --- a/src/Erl/Process.purs +++ b/src/Erl/Process.purs @@ -11,6 +11,7 @@ module Erl.Process , receiveWithTimeout , spawn , spawnLink + , sendExitSignal , class HasProcess , class ReceivesMessage , class HasSelf @@ -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 @@ -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 diff --git a/src/Erl/Process/Raw.erl b/src/Erl/Process/Raw.erl index ab4a2ad..1a5b665 100644 --- a/src/Erl/Process/Raw.erl +++ b/src/Erl/Process/Raw.erl @@ -11,6 +11,7 @@ self/0, setProcessFlagTrapExit/1, exit/1, + sendExitSignal/2, unlink/1 ]). @@ -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. diff --git a/src/Erl/Process/Raw.purs b/src/Erl/Process/Raw.purs index aee500c..5bc7755 100644 --- a/src/Erl/Process/Raw.purs +++ b/src/Erl/Process/Raw.purs @@ -14,6 +14,7 @@ module Erl.Process.Raw , class HasPid , getPid , exit + , sendExitSignal , unlink ) where @@ -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