Safe Haskell | None |
---|---|
Language | Haskell2010 |
Observer Effects
This module supports the implementation of observerRegistry and observables. Expected use case is event propagation.
The observable event sources and the observers are usually server processes for a
protocol that embeds the ObserverRegistry
and Observer
Pdu
s respectively.
A generic FIFO queue based observer can be found in Control.Eff.Concurrent.Protocol.Observer.Queue.
Since: 0.16.0
Synopsis
- newtype Observer event = MkObserver (Arg ProcessId (ObservationSink event))
- data ObservationSink event
- type IsObservable eventSource event = (Tangible event, Embeds eventSource (ObserverRegistry event), HasPdu eventSource)
- type CanObserve eventSink event = (Tangible event, Embeds eventSink (Observer event), HasPdu eventSink)
- data family Pdu protocol (reply :: Synchronicity)
- registerObserver :: forall event eventSink eventSource r q. (HasCallStack, HasProcesses r q, IsObservable eventSource event, Tangible (Pdu eventSource Asynchronous), Tangible (Pdu eventSink Asynchronous), CanObserve eventSink event) => Endpoint eventSource -> Endpoint eventSink -> Eff r ()
- forgetObserver :: forall event eventSink eventSource r q. (HasProcesses r q, HasCallStack, Tangible (Pdu eventSource Asynchronous), Tangible (Pdu eventSink Asynchronous), IsObservable eventSource event, CanObserve eventSink event) => Endpoint eventSource -> Endpoint eventSink -> Eff r ()
- forgetObserverUnsafe :: forall event eventSource r q. (HasProcesses r q, HasCallStack, Tangible (Pdu eventSource Asynchronous), IsObservable eventSource event) => Endpoint eventSource -> ProcessId -> Eff r ()
- data ObserverRegistry (event :: Type) = MkObserverRegistry {
- _observerRegistry :: Map ProcessId (ObservationSink event)
- type ObserverRegistryState event = State (ObserverRegistry event)
- observerRegistryNotify :: forall event r q. (HasProcesses r q, Member (ObserverRegistryState event) r, Tangible event, HasCallStack) => event -> Eff r ()
- evalObserverRegistryState :: HasCallStack => Eff (ObserverRegistryState event ': r) a -> Eff r a
- emptyObserverRegistry :: ObserverRegistry event
- observerRegistryHandlePdu :: forall event q r. (HasCallStack, Typeable event, HasProcesses r q, Member (ObserverRegistryState event) r, Member Logs r) => Pdu (ObserverRegistry event) Asynchronous -> Eff r ()
- observerRegistryRemoveProcess :: forall event q r. (HasCallStack, Typeable event, HasProcesses r q, Member (ObserverRegistryState event) r, Member Logs r) => ProcessId -> Eff r Bool
Documentation
newtype Observer event Source #
A protocol to communicate Observed
events from a sources to many sinks.
A sink is any process that serves a protocol with a Pdu
instance that embeds
the Observer
Pdu via an HasPduPrism
instance.
This type has dual use, for one it serves as type-index for Pdu
, i.e.
HasPdu
respectively, and secondly it contains an ObservationSink
and
a MonitorReference
.
The ObservationSink
is used to serialize and send the Observed
events,
while the ProcessId
serves as key for internal maps.
Since: 0.28.0
MkObserver (Arg ProcessId (ObservationSink event)) |
Instances
data ObservationSink event Source #
The Information necessary to wrap an Observed
event to a process specific
message, e.g. the embedded Observer
Pdu
instance, and the MonitorReference
of
the destination process.
Since: 0.28.0
Instances
type IsObservable eventSource event = (Tangible event, Embeds eventSource (ObserverRegistry event), HasPdu eventSource) Source #
Convenience type alias.
Since: 0.28.0
type CanObserve eventSink event = (Tangible event, Embeds eventSink (Observer event), HasPdu eventSink) Source #
Convenience type alias.
Since: 0.28.0
data family Pdu protocol (reply :: Synchronicity) Source #
The protocol data unit type for the given protocol.
Instances
registerObserver :: forall event eventSink eventSource r q. (HasCallStack, HasProcesses r q, IsObservable eventSource event, Tangible (Pdu eventSource Asynchronous), Tangible (Pdu eventSink Asynchronous), CanObserve eventSink event) => Endpoint eventSource -> Endpoint eventSink -> Eff r () Source #
And an Observer
to the set of recipients for all observations reported by observerRegistryNotify
.
Note that the observerRegistry 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 :: forall event eventSink eventSource r q. (HasProcesses r q, HasCallStack, Tangible (Pdu eventSource Asynchronous), Tangible (Pdu eventSink Asynchronous), IsObservable eventSource event, CanObserve eventSink event) => Endpoint eventSource -> Endpoint eventSink -> Eff r () Source #
Send the ForgetObserver
message
Since: 0.16.0
forgetObserverUnsafe :: forall event eventSource r q. (HasProcesses r q, HasCallStack, Tangible (Pdu eventSource Asynchronous), IsObservable eventSource event) => Endpoint eventSource -> ProcessId -> Eff r () Source #
Send the ForgetObserver
message, use a raw ProcessId
as parameter.
Since: 0.28.0
data ObserverRegistry (event :: Type) Source #
A protocol for managing Observer
s, encompassing registration and de-registration of
Observer
s.
Since: 0.28.0
Instances
type ObserverRegistryState event = State (ObserverRegistry event) Source #
Alias for the effect that contains the observers managed by evalObserverRegistryState
observerRegistryNotify :: forall event r q. (HasProcesses r q, Member (ObserverRegistryState event) r, Tangible event, HasCallStack) => event -> Eff r () Source #
Report an observation to all observers.
The process needs to evalObserverRegistryState
and to observerRegistryHandlePdu
.
Since: 0.28.0
evalObserverRegistryState :: HasCallStack => Eff (ObserverRegistryState event ': r) a -> Eff r a Source #
Keep track of registered Observer
s.
Handle the ObserverRegistryState
effect, i.e. run evalState
on an emptyObserverRegistry
.
Since: 0.28.0
emptyObserverRegistry :: ObserverRegistry event Source #
The empty ObserverRegistryState
Since: 0.28.0
observerRegistryHandlePdu :: forall event q r. (HasCallStack, Typeable event, HasProcesses r q, Member (ObserverRegistryState event) r, Member Logs r) => Pdu (ObserverRegistry event) Asynchronous -> Eff r () Source #
Provide the implementation for the ObserverRegistry
Protocol, this handled RegisterObserver
and ForgetObserver
messages. It also adds the ObserverRegistryState
constraint to the effect list.
Since: 0.28.0
observerRegistryRemoveProcess :: forall event q r. (HasCallStack, Typeable event, HasProcesses r q, Member (ObserverRegistryState event) r, Member Logs r) => ProcessId -> Eff r Bool Source #
Remove the entry in the ObserverRegistry
for the ProcessId
and return True
if there was an entry, False
otherwise.
Since: 0.28.0