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.
Synopsis
- 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 LogMessage) q) => SchedulerProxy q -> (Server o -> Observation o -> Eff (Process q ': q) Bool) -> Eff r (Server (CallbackObserver o))
- spawnLoggingObserver :: forall o r q. (SetMember Process (Process q) r, Typeable o, Show (Observation o), Observable o, Member (Logs LogMessage) q) => SchedulerProxy q -> Eff r (Server (CallbackObserver o))
Observation API
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.
Instances
Observable o => Observer (CallbackObserver o) o Source # | |
Defined in Control.Eff.Concurrent.Api.Observer observationMessage :: Server o -> Observation o -> Api (CallbackObserver o) Asynchronous 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
Generalized observation
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 |
Instances
Eq (SomeObserver o) Source # | |
Defined in Control.Eff.Concurrent.Api.Observer (==) :: SomeObserver o -> SomeObserver o -> Bool # (/=) :: SomeObserver o -> SomeObserver o -> Bool # | |
Ord (SomeObserver o) Source # | |
Defined in Control.Eff.Concurrent.Api.Observer compare :: SomeObserver o -> SomeObserver o -> Ordering # (<) :: SomeObserver o -> SomeObserver o -> Bool # (<=) :: SomeObserver o -> SomeObserver o -> Bool # (>) :: SomeObserver o -> SomeObserver o -> Bool # (>=) :: SomeObserver o -> SomeObserver o -> Bool # max :: SomeObserver o -> SomeObserver o -> SomeObserver o # min :: SomeObserver o -> SomeObserver o -> SomeObserver o # | |
Show (SomeObserver o) Source # | |
Defined in Control.Eff.Concurrent.Api.Observer showsPrec :: Int -> SomeObserver o -> ShowS # show :: SomeObserver o -> String # showList :: [SomeObserver o] -> ShowS # |
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.
Callback Observer
data CallbackObserver o Source #
An Observer
that schedules the observations to an effectful callback.
Instances
Show (Observation o) => Show (Api (CallbackObserver o) r) Source # | |
Defined in Control.Eff.Concurrent.Api.Observer | |
Observable o => Observer (CallbackObserver o) o Source # | |
Defined in Control.Eff.Concurrent.Api.Observer observationMessage :: Server o -> Observation o -> Api (CallbackObserver o) Asynchronous Source # | |
data Api (CallbackObserver o) r Source # | |
Defined in Control.Eff.Concurrent.Api.Observer |
spawnCallbackObserver :: forall o r q. (SetMember Process (Process q) r, Typeable o, Show (Observation o), Observable o, Member (Logs LogMessage) 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.
spawnLoggingObserver :: forall o r q. (SetMember Process (Process q) r, Typeable o, Show (Observation o), Observable o, Member (Logs LogMessage) q) => SchedulerProxy q -> Eff r (Server (CallbackObserver o)) Source #
Use spawnCallbackObserver
to create a universal logging observer,
using the Show
instance of the Observation
.
| Start a new process for an Observer
that schedules
all observations to an effectful callback.
Since: extensible-effects-concurrent-0.3.0.0