Skip to content

Commit

Permalink
Changed timeouts to take Data.Time.Duration.Milliseconds
Browse files Browse the repository at this point in the history
  • Loading branch information
srstrong authored and nwolverson committed Oct 12, 2021
1 parent ae06006 commit 2975184
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/Erl/Process.purs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module Erl.Process

import Prelude
import Data.Either (Either)
import Data.Time.Duration (Milliseconds(..))
import Effect (Effect)
import Effect.Class (class MonadEffect, liftEffect)
import Erl.Process.Raw (ExitReason(..), ExitMsg(..)) as RawExport
Expand Down Expand Up @@ -55,7 +56,7 @@ instance monadEffectProcessM :: MonadEffect (ProcessM a) where
receive :: forall a. ProcessM a a
receive = ProcessM Raw.receive

receiveWithTimeout :: forall a. Int -> a -> ProcessM a a
receiveWithTimeout :: forall a. Milliseconds -> a -> ProcessM a a
receiveWithTimeout n a = ProcessM $ Raw.receiveWithTimeout n a

newtype ProcessTrapM (a :: Type) b
Expand All @@ -72,7 +73,7 @@ instance monadEffectProcessTrapM :: MonadEffect (ProcessTrapM a) where
receiveWithTrap :: forall a. ProcessTrapM a (Either ExitReason a)
receiveWithTrap = ProcessTrapM Raw.receiveWithTrap

receiveWithTrapAndTimeout :: forall a. Int -> a -> ProcessTrapM a (Either ExitReason a)
receiveWithTrapAndTimeout :: forall a. Milliseconds -> a -> ProcessTrapM a (Either ExitReason a)
receiveWithTrapAndTimeout timeout default = ProcessTrapM $ Raw.receiveWithTrapAndTimeout timeout default

trapExit :: forall a b. ProcessTrapM a b -> ProcessM a b
Expand Down
8 changes: 4 additions & 4 deletions src/Erl/Process/Raw.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
spawnLink/1,
send/1,
'receive'/0,
receiveWithTimeout/2,
receiveWithTimeout_/2,
receiveWithTrap/0,
receiveWithTrapAndTimeout/2,
receiveWithTrapAndTimeout_/2,
self/0,
setProcessFlagTrapExit/1,
exit/1,
Expand All @@ -30,7 +30,7 @@ end.
receive X -> X end
end.

receiveWithTimeout(Timeout, Msg) ->
receiveWithTimeout_(Timeout, Msg) ->
fun () ->
receive
X -> X
Expand All @@ -53,7 +53,7 @@ receiveWithTrap() ->
end
end.

receiveWithTrapAndTimeout(Timeout, Msg) ->
receiveWithTrapAndTimeout_(Timeout, Msg) ->
fun () ->
receive
{'EXIT', Pid, killed} -> {left, {exitMsg, Pid, {killed}}};
Expand Down
12 changes: 10 additions & 2 deletions src/Erl/Process/Raw.purs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ module Erl.Process.Raw

import Prelude
import Data.Either (Either)
import Data.Int (round)
import Data.Time.Duration (Milliseconds(..))
import Effect (Effect)
import Foreign (Foreign)

Expand All @@ -36,7 +38,10 @@ foreign import send :: forall a. Pid -> a -> Effect Unit

foreign import receive :: forall a. Effect a

foreign import receiveWithTimeout :: forall a. Int -> a -> Effect a
receiveWithTimeout :: forall a. Milliseconds -> a -> Effect a
receiveWithTimeout (Milliseconds ms) = receiveWithTimeout_ (round ms)

foreign import receiveWithTimeout_ :: forall a. Int -> a -> Effect a

foreign import self :: Effect Pid

Expand All @@ -55,7 +60,10 @@ data ExitMsg

foreign import receiveWithTrap :: forall a. Effect (Either ExitReason a)

foreign import receiveWithTrapAndTimeout :: forall a. Int -> a -> Effect (Either ExitReason a)
receiveWithTrapAndTimeout :: forall a. Milliseconds -> a -> Effect (Either ExitReason a)
receiveWithTrapAndTimeout (Milliseconds ms) = receiveWithTrapAndTimeout_ (round ms)

foreign import receiveWithTrapAndTimeout_ :: forall a. Int -> a -> Effect (Either ExitReason a)

foreign import setProcessFlagTrapExit :: Boolean -> Effect Boolean

Expand Down

0 comments on commit 2975184

Please sign in to comment.