Safe Haskell | None |
---|---|
Language | Haskell2010 |
Observer Effects
This module supports the implementation of observers and observables. Expected use case is event propagation.
Since: 0.16.0
Synopsis
- data Observer o where
- type TangibleObserver o = (Tangible o, IsPdu (Observer o) Asynchronous)
- data family Pdu protocol reply
- registerObserver :: (SetMember Process (Process q) r, HasCallStack, Member Interrupts r, TangibleObserver o, EmbedProtocol x (ObserverRegistry o), IsPdu x Asynchronous) => Observer o -> Endpoint x -> Eff r ()
- forgetObserver :: (SetMember Process (Process q) r, HasCallStack, Member Interrupts r, Typeable o, NFData o, EmbedProtocol x (ObserverRegistry o), IsPdu x Asynchronous) => Observer o -> Endpoint x -> Eff r ()
- handleObservations :: (HasCallStack, Typeable o, SetMember Process (Process q) r, NFData (Observer o)) => (o -> Eff r ()) -> Pdu (Observer o) Asynchronous -> Eff r ()
- toObserver :: forall o p. (IsPdu p Asynchronous, EmbedProtocol p (Observer o), TangibleObserver o) => Endpoint p -> Observer o
- toObserverFor :: (TangibleObserver o, Typeable a, IsPdu a Asynchronous) => (o -> Pdu a Asynchronous) -> Endpoint a -> Observer o
- data ObserverRegistry (o :: Type)
- type ObserverState o = State (Observers o)
- data Observers o
- emptyObservers :: Observers o
- handleObserverRegistration :: forall o q r. (HasCallStack, Typeable o, SetMember Process (Process q) r, Member (ObserverState o) r, Member Logs r) => Pdu (ObserverRegistry o) Asynchronous -> Eff r ()
- manageObservers :: Eff (ObserverState o ': r) a -> Eff r a
- observed :: forall o r q. (SetMember Process (Process q) r, Member (ObserverState o) r, Member Interrupts r, TangibleObserver o) => o -> Eff r ()
Documentation
data Observer o where Source #
Describes a process that observes another via Asynchronous
Pdu
messages.
An observer consists of a filter and a process id. The filter converts an observation to
a message understood by the observer process, and the ProcessId
is used to send the message.
Since: 0.16.0
Observer :: (Tangible o, IsPdu p Asynchronous, Tangible (Endpoint p), Typeable p) => (o -> Maybe (Pdu p Asynchronous)) -> Endpoint p -> Observer o |
Instances
Eq (Observer o) Source # | |
Ord (Observer o) Source # | |
Defined in Control.Eff.Concurrent.Protocol.Observer | |
Show (Observer o) Source # | |
NFData o => NFData (Observer o) Source # | |
Defined in Control.Eff.Concurrent.Protocol.Observer | |
(NFData o, Show o, Typeable o, Typeable r) => IsPdu (Observer o) r Source # | A minimal Protocol for handling observations.
This is one simple way of receiving observations - of course users can use
any other Since: 0.16.0 |
Show o => Show (Pdu (Observer o) r) Source # | |
NFData o => NFData (Pdu (Observer o) r) Source # | |
Defined in Control.Eff.Concurrent.Protocol.Observer | |
data Pdu (Observer o) r Source # | |
Defined in Control.Eff.Concurrent.Protocol.Observer data Pdu (Observer o) r where
| |
type ToPretty (Observer o :: Type) Source # | |
Defined in Control.Eff.Concurrent.Protocol.Observer |
type TangibleObserver o = (Tangible o, IsPdu (Observer o) Asynchronous) Source #
The constraints on the type parameters to an Observer
Since: 0.24.0
data family Pdu protocol reply Source #
The protocol data unit type for the given protocol.
Instances
registerObserver :: (SetMember Process (Process q) r, HasCallStack, Member Interrupts r, TangibleObserver o, EmbedProtocol x (ObserverRegistry o), IsPdu x Asynchronous) => Observer o -> Endpoint x -> Eff r () Source #
And an Observer
to the set of recipients for all observations reported by observed
.
Note that the observers are keyed by the observing process, i.e. a previous entry for the process
contained in the Observer
is overwritten. If you want multiple entries for a single process, just
combine several filter functions.
Since: 0.16.0
forgetObserver :: (SetMember Process (Process q) r, HasCallStack, Member Interrupts r, Typeable o, NFData o, EmbedProtocol x (ObserverRegistry o), IsPdu x Asynchronous) => Observer o -> Endpoint x -> Eff r () Source #
Send the ForgetObserver
message
Since: 0.16.0
handleObservations :: (HasCallStack, Typeable o, SetMember Process (Process q) r, NFData (Observer o)) => (o -> Eff r ()) -> Pdu (Observer o) Asynchronous -> Eff r () Source #
Based on the Pdu
instance for Observer
this simplified writing
a callback handler for observations. In order to register to
and ObserverRegistry
use toObserver
.
Since: 0.16.0
toObserver :: forall o p. (IsPdu p Asynchronous, EmbedProtocol p (Observer o), TangibleObserver o) => Endpoint p -> Observer o Source #
Use a Endpoint
as an Observer
for handleObservations
.
Since: 0.16.0
toObserverFor :: (TangibleObserver o, Typeable a, IsPdu a Asynchronous) => (o -> Pdu a Asynchronous) -> Endpoint a -> Observer o Source #
data ObserverRegistry (o :: Type) Source #
A protocol for managing Observer
s, encompassing registration and de-registration of
Observer
s.
Since: 0.16.0
Instances
(Typeable o, Typeable r) => IsPdu (ObserverRegistry o) r Source # | |
Defined in Control.Eff.Concurrent.Protocol.Observer data Pdu (ObserverRegistry o) r :: Type Source # deserializePdu :: Dynamic -> Maybe (Pdu (ObserverRegistry o) r) Source # | |
Show (Pdu (ObserverRegistry o) r) Source # | |
Defined in Control.Eff.Concurrent.Protocol.Observer | |
NFData (Pdu (ObserverRegistry o) r) Source # | |
Defined in Control.Eff.Concurrent.Protocol.Observer rnf :: Pdu (ObserverRegistry o) r -> () # | |
data Pdu (ObserverRegistry o) r Source # | |
Defined in Control.Eff.Concurrent.Protocol.Observer data Pdu (ObserverRegistry o) r where
| |
type ToPretty (ObserverRegistry o :: Type) Source # | |
Defined in Control.Eff.Concurrent.Protocol.Observer |
type ObserverState o = State (Observers o) Source #
Alias for the effect that contains the observers managed by manageObservers
Internal state for manageObservers
Instances
Eq (Observers o) Source # | |
Ord (Observers o) Source # | |
Defined in Control.Eff.Concurrent.Protocol.Observer | |
Show (Observers o) Source # | |
NFData o => NFData (Observers o) Source # | |
Defined in Control.Eff.Concurrent.Protocol.Observer |
emptyObservers :: Observers o Source #
The empty ObserverState
Since: 0.24.0
handleObserverRegistration :: forall o q r. (HasCallStack, Typeable o, SetMember Process (Process q) r, Member (ObserverState o) r, Member Logs r) => Pdu (ObserverRegistry o) Asynchronous -> Eff r () Source #
Provide the implementation for the ObserverRegistry
Protocol, this handled RegisterObserver
and ForgetObserver
messages. It also adds the ObserverState
constraint to the effect list.
Since: 0.16.0
manageObservers :: Eff (ObserverState o ': r) a -> Eff r a Source #
Keep track of registered Observer
s.
Handle the ObserverState
introduced by handleObserverRegistration
.
Since: 0.16.0
observed :: forall o r q. (SetMember Process (Process q) r, Member (ObserverState o) r, Member Interrupts r, TangibleObserver o) => o -> Eff r () Source #
Report an observation to all observers.
The process needs to manageObservers
and to handleObserverRegistration
.
Since: 0.16.0