module Polysemy.Conc.Events where
import qualified Polysemy.Conc.Effect.Events as Events
import Polysemy.Conc.Interpreter.Events (EventConsumer)
subscribeWhile ::
∀ e token r .
Member (EventConsumer token e) r =>
(e -> Sem r Bool) ->
Sem r ()
subscribeWhile :: forall e token (r :: [(* -> *) -> * -> *]).
Member (EventConsumer token e) r =>
(e -> Sem r Bool) -> Sem r ()
subscribeWhile e -> Sem r Bool
action =
forall e resource (r :: [(* -> *) -> * -> *]).
Member (Scoped (EventResource resource) (Consume e)) r =>
InterpreterFor (Consume e) r
Events.subscribe @e @token Sem (Consume e : r) ()
spin
where
spin :: Sem (Consume e : r) ()
spin =
Sem (Consume e : r) Bool
-> Sem (Consume e : r) () -> Sem (Consume e : r) ()
forall (m :: * -> *). Monad m => m Bool -> m () -> m ()
whenM (Sem r Bool -> Sem (Consume e : r) Bool
forall (e :: (* -> *) -> * -> *) (r :: [(* -> *) -> * -> *]) a.
Sem r a -> Sem (e : r) a
raise (Sem r Bool -> Sem (Consume e : r) Bool)
-> (e -> Sem r Bool) -> e -> Sem (Consume e : r) Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> Sem r Bool
action (e -> Sem (Consume e : r) Bool)
-> Sem (Consume e : r) e -> Sem (Consume e : r) Bool
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Sem (Consume e : r) e
forall e (r :: [(* -> *) -> * -> *]).
Member (Consume e) r =>
Sem r e
Events.consume) Sem (Consume e : r) ()
spin
subscribeLoop ::
∀ e token r .
Member (EventConsumer token e) r =>
(e -> Sem r ()) ->
Sem r ()
subscribeLoop :: forall e token (r :: [(* -> *) -> * -> *]).
Member (EventConsumer token e) r =>
(e -> Sem r ()) -> Sem r ()
subscribeLoop e -> Sem r ()
action =
forall e resource (r :: [(* -> *) -> * -> *]).
Member (Scoped (EventResource resource) (Consume e)) r =>
InterpreterFor (Consume e) r
Events.subscribe @e @token (Sem (Consume e : r) () -> Sem (Consume e : r) ()
forall (f :: * -> *) a b. Applicative f => f a -> f b
forever (Sem r () -> Sem (Consume e : r) ()
forall (e :: (* -> *) -> * -> *) (r :: [(* -> *) -> * -> *]) a.
Sem r a -> Sem (e : r) a
raise (Sem r () -> Sem (Consume e : r) ())
-> (e -> Sem r ()) -> e -> Sem (Consume e : r) ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> Sem r ()
action (e -> Sem (Consume e : r) ())
-> Sem (Consume e : r) e -> Sem (Consume e : r) ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Sem (Consume e : r) e
forall e (r :: [(* -> *) -> * -> *]).
Member (Consume e) r =>
Sem r e
Events.consume))