Safe Haskell | None |
---|---|
Language | Haskell2010 |
Observer Effects
This module supports the implementation of observers and observables. One use
case is event propagation. The tools in this module are tailored towards
Api
servers/clients.
- class (Typeable p, Observable o) => Observer p o where
- class (Typeable o, Typeable (Observation o)) => Observable o where
- data Observation o
- notifyObserver :: (SetMember Process (Process q) r, Observable o, Observer p o, HasCallStack) => SchedulerProxy q -> Server p -> Server o -> Observation o -> Eff r ()
- registerObserver :: (SetMember Process (Process q) r, Observable o, Observer p o, HasCallStack) => SchedulerProxy q -> Server p -> Server o -> Eff r ()
- forgetObserver :: (SetMember Process (Process q) r, Observable o, Observer p o) => SchedulerProxy q -> Server p -> Server o -> Eff r ()
- data SomeObserver o where
- SomeObserver :: (Show (Server p), Typeable p, Observer p o) => Server p -> SomeObserver o
- notifySomeObserver :: (SetMember Process (Process q) r, Observable o, HasCallStack) => SchedulerProxy q -> Server o -> Observation o -> SomeObserver o -> Eff r ()
- data Observers o
- manageObservers :: Eff (State (Observers o) ': r) a -> Eff r a
- addObserver :: (SetMember Process (Process q) r, Member (State (Observers o)) r, Observable o) => SomeObserver o -> Eff r ()
- removeObserver :: (SetMember Process (Process q) r, Member (State (Observers o)) r, Observable o) => SomeObserver o -> Eff r ()
- notifyObservers :: forall o r q. (Observable o, SetMember Process (Process q) r, Member (State (Observers o)) r) => SchedulerProxy q -> Observation o -> Eff r ()
- data CallbackObserver o
- spawnCallbackObserver :: forall o r q. (SetMember Process (Process q) r, Typeable o, Show (Observation o), Observable o, Member (Logs String) q) => SchedulerProxy q -> (Server o -> Observation o -> Eff (Process q ': q) Bool) -> Eff r (Server (CallbackObserver o))
Documentation
class (Typeable p, Observable o) => Observer p o where Source #
An Api
index that support observation of the
another Api
that is Observable
.
observationMessage :: Server o -> Observation o -> Api p Asynchronous Source #
Wrap the Observation
and the ProcessId
(i.e. the Server
)
that caused the observation into a Api
value that the
Observable
understands.
Observable o => Observer (CallbackObserver Type o) o Source # | |
class (Typeable o, Typeable (Observation o)) => Observable o where Source #
data Observation o Source #
Type of observations visible on this observable
registerObserverMessage :: SomeObserver o -> Api o Asynchronous Source #
Return the Api
value for the cast_
that registeres an observer
forgetObserverMessage :: SomeObserver o -> Api o Asynchronous Source #
Return the Api
value for the cast_
that de-registeres an observer
notifyObserver :: (SetMember Process (Process q) r, Observable o, Observer p o, HasCallStack) => SchedulerProxy q -> Server p -> Server o -> Observation o -> Eff r () Source #
Send an Observation
to an Observer
registerObserver :: (SetMember Process (Process q) r, Observable o, Observer p o, HasCallStack) => SchedulerProxy q -> Server p -> Server o -> Eff r () Source #
Send the registerObserverMessage
forgetObserver :: (SetMember Process (Process q) r, Observable o, Observer p o) => SchedulerProxy q -> Server p -> Server o -> Eff r () Source #
Send the forgetObserverMessage
data SomeObserver o where Source #
An existential wrapper around a Server
of an Observer
.
Needed to support different types of observers to observe the
same Observable
in a general fashion.
SomeObserver :: (Show (Server p), Typeable p, Observer p o) => Server p -> SomeObserver o |
Eq (SomeObserver o) Source # | |
Ord (SomeObserver o) Source # | |
Show (SomeObserver o) Source # | |
notifySomeObserver :: (SetMember Process (Process q) r, Observable o, HasCallStack) => SchedulerProxy q -> Server o -> Observation o -> SomeObserver o -> Eff r () Source #
Send an Observation
to SomeObserver
.
manageObservers :: Eff (State (Observers o) ': r) a -> Eff r a Source #
Keep track of registered Observer
s Observers can be added and removed,
and an Observation
can be sent to all registerd observers at once.
addObserver :: (SetMember Process (Process q) r, Member (State (Observers o)) r, Observable o) => SomeObserver o -> Eff r () Source #
Add an Observer
to the Observers
managed by manageObservers
.
removeObserver :: (SetMember Process (Process q) r, Member (State (Observers o)) r, Observable o) => SomeObserver o -> Eff r () Source #
Delete an Observer
from the Observers
managed by manageObservers
.
notifyObservers :: forall o r q. (Observable o, SetMember Process (Process q) r, Member (State (Observers o)) r) => SchedulerProxy q -> Observation o -> Eff r () Source #
Send an Observation
to all SomeObserver
s in the Observers
state.
data CallbackObserver o Source #
An Observer
that schedules the observations to an effectful callback.
Show (Observation o) => Show (Api (CallbackObserver Type o) r) Source # | |
Observable o => Observer (CallbackObserver Type o) o Source # | |
data Api (CallbackObserver k o) Source # | |
spawnCallbackObserver :: forall o r q. (SetMember Process (Process q) r, Typeable o, Show (Observation o), Observable o, Member (Logs String) q) => SchedulerProxy q -> (Server o -> Observation o -> Eff (Process q ': q) Bool) -> Eff r (Server (CallbackObserver o)) Source #
Start a new process for an Observer
that schedules
all observations to an effectful callback.