Safe Haskell | None |
---|---|
Language | Haskell2010 |
Utilities to implement server-loops with builtin state and TEA-like naming.
Since: 0.24.0
Synopsis
- class Typeable (Protocol a) => Server (a :: Type) q where
- data StartArgument a q
- type Protocol a :: Type
- type Model a :: Type
- type Settings a :: Type
- setup :: Endpoint (Protocol a) -> StartArgument a q -> Eff q (Model a, Settings a)
- update :: Endpoint (Protocol a) -> StartArgument a q -> Event (Protocol a) -> Eff (ModelState a ': (SettingsReader a ': q)) ()
- data Stateful a
- data family Init a e
- start :: forall a r q h. (HasCallStack, Typeable a, LogsTo h (Processes q), Server (Stateful a) (Processes q), Server a (Processes q), HasProcesses r q) => StartArgument a (Processes q) -> Eff r (Endpoint (Protocol a))
- startLink :: forall a r q h. (HasCallStack, Typeable a, LogsTo h (Processes q), Server (Stateful a) (Processes q), Server a (Processes q), HasProcesses r q) => StartArgument a (Processes q) -> Eff r (Endpoint (Protocol a))
- type ModelState a = State (Model a)
- modifyModel :: forall a e. Member (ModelState a) e => (Model a -> Model a) -> Eff e ()
- getAndModifyModel :: forall a e. Member (ModelState a) e => (Model a -> Model a) -> Eff e (Model a)
- modifyAndGetModel :: forall a e. Member (ModelState a) e => (Model a -> Model a) -> Eff e (Model a)
- getModel :: forall a e. Member (ModelState a) e => Eff e (Model a)
- putModel :: forall a e. Member (ModelState a) e => Model a -> Eff e ()
- getAndPutModel :: forall a e. Member (ModelState a) e => Model a -> Eff e (Model a)
- useModel :: forall a b e. Member (ModelState a) e => Getting b (Model a) b -> Eff e b
- zoomModel :: forall a b c e. Member (ModelState a) e => Lens' (Model a) b -> Eff (State b ': e) c -> Eff e c
- type SettingsReader a = Reader (Settings a)
- askSettings :: forall a e. Member (SettingsReader a) e => Eff e (Settings a)
- viewSettings :: forall a b e. Member (SettingsReader a) e => Getting b (Settings a) b -> Eff e b
- data Event a where
- OnCall :: forall a r. (Tangible r, TangiblePdu a (Synchronous r)) => ReplyTarget a r -> Pdu a (Synchronous r) -> Event a
- OnCast :: forall a. TangiblePdu a Asynchronous => Pdu a Asynchronous -> Event a
- OnInterrupt :: Interrupt Recoverable -> Event a
- OnDown :: ProcessDown -> Event a
- OnTimeOut :: TimerElapsed -> Event a
- OnMessage :: StrictDynamic -> Event a
Documentation
class Typeable (Protocol a) => Server (a :: Type) q where Source #
A type class for server loops.
This class serves as interface for other mechanisms, for example process supervision
The methods of this class handle Event
s and Request
s for Pdu
instances.
Instances can by index types for Pdu
family directly, or indirectly via the ServerPdu
type family.
To builder servers serving multiple protocols, use the generic Pdu
instances, for which Embeds
instances exist, like 2-,3-,4-, or 5-tuple.
The naming is inspired by The Elm Architecture, without the view
callback.
This class is based on Control.Eff.Concurrent.Protocol.EffectfulServer and adds a default
State
and Reader
effect.
Since: 0.24.0
data StartArgument a q Source #
The value that defines what is required to initiate a Server
loop.
type Protocol a :: Type Source #
The index type of the Event
s that this server processes.
This is the first parameter to the Request
and therefore of
the Pdu
family.
Type of the model data, given to every invocation of update
via the ModelState
effect.
The model of a server loop is changed through incoming Event
s.
It is initially calculated by setup
.
type Settings a :: Type Source #
Type of read-only state.
setup :: Endpoint (Protocol a) -> StartArgument a q -> Eff q (Model a, Settings a) Source #
setup :: (Default (Model a), Default (Settings a)) => Endpoint (Protocol a) -> StartArgument a q -> Eff q (Model a, Settings a) Source #
update :: Endpoint (Protocol a) -> StartArgument a q -> Event (Protocol a) -> Eff (ModelState a ': (SettingsReader a ': q)) () Source #
Update the Model
based on the Event
.
Instances
This type is used to build stateful EffectfulServer
instances.
It is a variant of EffectfulServer
, that comes pre-installed
with State
and Reader
effects.
Since: 0.24.0
Instances
Server a q => Server (Stateful a) q Source # | |
Defined in Control.Eff.Concurrent.Protocol.StatefulServer data Init (Stateful a) q :: Type Source # type ServerPdu (Stateful a) :: Type Source # type ServerEffects (Stateful a) q :: [Type -> Type] Source # serverTitle :: Init (Stateful a) q -> ProcessTitle Source # runEffects :: Endpoint (ServerPdu (Stateful a)) -> Init (Stateful a) q -> Eff (ServerEffects (Stateful a) q) x -> Eff q x Source # onEvent :: Endpoint (ServerPdu (Stateful a)) -> Init (Stateful a) q -> Event (ServerPdu (Stateful a)) -> Eff (ServerEffects (Stateful a) q) () Source # | |
data Init (Stateful a) q Source # | |
type ServerPdu (Stateful a) Source # | |
type ServerEffects (Stateful a) q Source # | |
The value that defines what is required to initiate a Server
loop.
Instances
TangibleCallbacks tag eLoop e => Show (Init (Server tag eLoop) (Processes e)) Source # | |
TangibleCallbacks tag eLoop e => NFData (Init (Server tag eLoop) (Processes e)) Source # | |
data Init (Stateful a) q Source # | |
data Init (Server tag eLoop) (Processes e) Source # | |
Defined in Control.Eff.Concurrent.Protocol.CallbackServer data Init (Server tag eLoop) (Processes e) = MkServer {
|
start :: forall a r q h. (HasCallStack, Typeable a, LogsTo h (Processes q), Server (Stateful a) (Processes q), Server a (Processes q), HasProcesses r q) => StartArgument a (Processes q) -> Eff r (Endpoint (Protocol a)) Source #
Execute the server loop.
Since: 0.24.0
startLink :: forall a r q h. (HasCallStack, Typeable a, LogsTo h (Processes q), Server (Stateful a) (Processes q), Server a (Processes q), HasProcesses r q) => StartArgument a (Processes q) -> Eff r (Endpoint (Protocol a)) Source #
Execute the server loop.
Since: 0.24.0
type ModelState a = State (Model a) Source #
modifyModel :: forall a e. Member (ModelState a) e => (Model a -> Model a) -> Eff e () Source #
getAndModifyModel :: forall a e. Member (ModelState a) e => (Model a -> Model a) -> Eff e (Model a) Source #
modifyAndGetModel :: forall a e. Member (ModelState a) e => (Model a -> Model a) -> Eff e (Model a) Source #
getAndPutModel :: forall a e. Member (ModelState a) e => Model a -> Eff e (Model a) Source #
zoomModel :: forall a b c e. Member (ModelState a) e => Lens' (Model a) b -> Eff (State b ': e) c -> Eff e c Source #
type SettingsReader a = Reader (Settings a) Source #
askSettings :: forall a e. Member (SettingsReader a) e => Eff e (Settings a) Source #
viewSettings :: forall a b e. Member (SettingsReader a) e => Getting b (Settings a) b -> Eff e b Source #
Re-exports
This event sum-type is used to communicate incoming messages and other events to the
instances of Server
.
Since: 0.24.0
OnCall :: forall a r. (Tangible r, TangiblePdu a (Synchronous r)) => ReplyTarget a r -> Pdu a (Synchronous r) -> Event a | A Since: 0.24.1 |
OnCast :: forall a. TangiblePdu a Asynchronous => Pdu a Asynchronous -> Event a | |
OnInterrupt :: Interrupt Recoverable -> Event a | |
OnDown :: ProcessDown -> Event a | |
OnTimeOut :: TimerElapsed -> Event a | |
OnMessage :: StrictDynamic -> Event a |