{-# options_haddock prune #-}
module Polysemy.Conc.Effect.Monitor where
import Polysemy.Scoped (Scoped_, scoped_)
import Polysemy.Time (NanoSeconds)
data Restart =
Restart
deriving stock (Restart -> Restart -> Bool
(Restart -> Restart -> Bool)
-> (Restart -> Restart -> Bool) -> Eq Restart
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Restart -> Restart -> Bool
$c/= :: Restart -> Restart -> Bool
== :: Restart -> Restart -> Bool
$c== :: Restart -> Restart -> Bool
Eq, Int -> Restart -> ShowS
[Restart] -> ShowS
Restart -> String
(Int -> Restart -> ShowS)
-> (Restart -> String) -> ([Restart] -> ShowS) -> Show Restart
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Restart] -> ShowS
$cshowList :: [Restart] -> ShowS
show :: Restart -> String
$cshow :: Restart -> String
showsPrec :: Int -> Restart -> ShowS
$cshowsPrec :: Int -> Restart -> ShowS
Show)
data Monitor (action :: Type) :: Effect where
Monitor :: m a -> Monitor action m a
makeSem_ ''Monitor
monitor ::
∀ action r a .
Member (Monitor action) r =>
Sem r a ->
Sem r a
type ScopedMonitor (action :: Type) =
Scoped_ (Monitor action)
type RestartingMonitor =
ScopedMonitor Restart
data MonitorCheck r =
MonitorCheck {
forall (r :: EffectRow). MonitorCheck r -> NanoSeconds
interval :: NanoSeconds,
forall (r :: EffectRow). MonitorCheck r -> MVar () -> Sem r ()
check :: MVar () -> Sem r ()
}
hoistMonitorCheck ::
(∀ x . Sem r x -> Sem r' x) ->
MonitorCheck r ->
MonitorCheck r'
hoistMonitorCheck :: forall (r :: EffectRow) (r' :: EffectRow).
(forall x. Sem r x -> Sem r' x)
-> MonitorCheck r -> MonitorCheck r'
hoistMonitorCheck forall x. Sem r x -> Sem r' x
f MonitorCheck {NanoSeconds
MVar () -> Sem r ()
check :: MVar () -> Sem r ()
interval :: NanoSeconds
$sel:check:MonitorCheck :: forall (r :: EffectRow). MonitorCheck r -> MVar () -> Sem r ()
$sel:interval:MonitorCheck :: forall (r :: EffectRow). MonitorCheck r -> NanoSeconds
..} =
MonitorCheck :: forall (r :: EffectRow).
NanoSeconds -> (MVar () -> Sem r ()) -> MonitorCheck r
MonitorCheck {$sel:check:MonitorCheck :: MVar () -> Sem r' ()
check = Sem r () -> Sem r' ()
forall x. Sem r x -> Sem r' x
f (Sem r () -> Sem r' ())
-> (MVar () -> Sem r ()) -> MVar () -> Sem r' ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MVar () -> Sem r ()
check, NanoSeconds
interval :: NanoSeconds
$sel:interval:MonitorCheck :: NanoSeconds
..}
withMonitor ::
∀ action r .
Member (ScopedMonitor action) r =>
InterpreterFor (Monitor action) r
withMonitor :: forall action (r :: EffectRow).
Member (ScopedMonitor action) r =>
InterpreterFor (Monitor action) r
withMonitor =
Sem (Monitor action : r) a -> Sem r a
forall (effect :: Effect) (r :: EffectRow).
Member (Scoped_ effect) r =>
InterpreterFor effect r
scoped_
restart ::
Member (ScopedMonitor Restart) r =>
InterpreterFor (Monitor Restart) r
restart :: forall (r :: EffectRow).
Member (ScopedMonitor Restart) r =>
InterpreterFor (Monitor Restart) r
restart =
Sem (Monitor Restart : r) a -> Sem r a
forall action (r :: EffectRow).
Member (ScopedMonitor action) r =>
InterpreterFor (Monitor action) r
withMonitor