extensible-effects-concurrent-0.24.2: Message passing concurrency as extensible-effect

Safe HaskellNone
LanguageHaskell2010

Control.Eff.Concurrent.Protocol.EffectfulServer

Contents

Description

Utilities to implement effectful server-loops.

Since: 0.24.0

Synopsis

Documentation

class Server (a :: Type) (e :: [Type -> Type]) where Source #

A type class for effectful server loops.

This type class serves as interface for other abstractions, for example process supervision

The methods of this class handle Events Requests for Pdu instance.

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 EmbedProtocol instances exist, like 2-,3-,4-, or 5-tuple.

Since: 0.24.1

Minimal complete definition

Nothing

Associated Types

data Init a e Source #

The value that defines what is required to initiate a Server loop.

type ServerPdu a :: Type Source #

The index type of the Events that this server processes. This is the first parameter to the Request and therefore of the Pdu family.

type Effects a e :: [Type -> Type] Source #

Effects of the implementation

Since: 0.24.1

Methods

serverTitle :: Init a e -> ProcessTitle Source #

Return the ProcessTitle.

Usually you should rely on the default implementation

serverTitle :: Typeable (ServerPdu a) => Init a e -> ProcessTitle Source #

Return the ProcessTitle.

Usually you should rely on the default implementation

runEffects :: Init a e -> Eff (Effects a e) x -> Eff e x Source #

Process the effects of the implementation

runEffects :: Effects a e ~ e => Init a e -> Eff (Effects a e) x -> Eff e x Source #

Process the effects of the implementation

onEvent :: Init a e -> Event (ServerPdu a) -> Eff (Effects a e) () Source #

Update the Model based on the Event.

onEvent :: (Show (Init a e), Member Logs (Effects a e)) => Init a e -> Event (ServerPdu a) -> Eff (Effects a e) () Source #

Update the Model based on the Event.

Instances
TangibleGenServer tag eLoop e => Server (GenServer tag eLoop e) (InterruptableProcess e) Source # 
Instance details

Defined in Control.Eff.Concurrent.Protocol.EffectfulServer

Associated Types

data Init (GenServer tag eLoop e) (InterruptableProcess e) :: Type Source #

type ServerPdu (GenServer tag eLoop e) :: Type Source #

type Effects (GenServer tag eLoop e) (InterruptableProcess e) :: [Type -> Type] Source #

data Event a where Source #

Internal protocol to communicate incoming messages and other events to the instances of Server.

Note that this is required to receive any kind of messages in protocolServerLoop.

Since: 0.24.0

Constructors

OnCall :: forall a r. (Tangible r, TangiblePdu a (Synchronous r)) => Serializer (Reply a r) -> RequestOrigin a r -> Pdu a (Synchronous r) -> Event a

A Synchronous message was received. If an implementation wants to delegate nested Pdus, it can contramap the reply Serializer such that the Reply received by the caller has the correct type.

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 
Instances
Show (Event a) Source # 
Instance details

Defined in Control.Eff.Concurrent.Protocol.EffectfulServer

Methods

showsPrec :: Int -> Event a -> ShowS #

show :: Event a -> String #

showList :: [Event a] -> ShowS #

NFData a => NFData (Event a) Source # 
Instance details

Defined in Control.Eff.Concurrent.Protocol.EffectfulServer

Methods

rnf :: Event a -> () #

type ToPretty (Event a :: Type) Source # 
Instance details

Defined in Control.Eff.Concurrent.Protocol.EffectfulServer

type ToPretty (Event a :: Type) = ToPretty a <+> PutStr "event"

GenServer

type TangibleGenServer tag eLoop e = (LogIo e, SetMember Process (Process e) eLoop, Member Interrupts eLoop, Typeable e, Typeable eLoop, Typeable tag) Source #

The constraints for a tangible GenServer instance.

Since: 0.24.1

data GenServer tag eLoop e Source #

Make a Server from a data record instead of type-class instance.

Sometimes it is much more concise to create an inline server-loop. In those cases it might not be practical to go through all this type class boilerplate.

In these cases specifying a server by from a set of callback functions seems much more appropriate.

This is such a helper. The GenServer is a record with to callbacks, and a Server instance that simply invokes the given callbacks.

Servers that are directly based on LogIo and InterruptableProcess effects.

The name prefix Gen indicates the inspiration from Erlang's gen_server module.

Since: 0.24.1

Instances
Typeable tag => Show (Init (GenServer tag eLoop e) (InterruptableProcess e)) Source # 
Instance details

Defined in Control.Eff.Concurrent.Protocol.EffectfulServer

Methods

showsPrec :: Int -> Init (GenServer tag eLoop e) (InterruptableProcess e) -> ShowS #

show :: Init (GenServer tag eLoop e) (InterruptableProcess e) -> String #

showList :: [Init (GenServer tag eLoop e) (InterruptableProcess e)] -> ShowS #

NFData (Init (GenServer tag eLoop e) (InterruptableProcess e)) Source # 
Instance details

Defined in Control.Eff.Concurrent.Protocol.EffectfulServer

Methods

rnf :: Init (GenServer tag eLoop e) (InterruptableProcess e) -> () #

TangibleGenServer tag eLoop e => Server (GenServer tag eLoop e) (InterruptableProcess e) Source # 
Instance details

Defined in Control.Eff.Concurrent.Protocol.EffectfulServer

Associated Types

data Init (GenServer tag eLoop e) (InterruptableProcess e) :: Type Source #

type ServerPdu (GenServer tag eLoop e) :: Type Source #

type Effects (GenServer tag eLoop e) (InterruptableProcess e) :: [Type -> Type] Source #

type ServerPdu (GenServer tag eLoop e) Source # 
Instance details

Defined in Control.Eff.Concurrent.Protocol.EffectfulServer

type ServerPdu (GenServer tag eLoop e) = tag
data Init (GenServer tag eLoop e) (InterruptableProcess e) Source # 
Instance details

Defined in Control.Eff.Concurrent.Protocol.EffectfulServer

type Effects (GenServer tag eLoop e) (InterruptableProcess e) Source # 
Instance details

Defined in Control.Eff.Concurrent.Protocol.EffectfulServer

type Effects (GenServer tag eLoop e) (InterruptableProcess e) = eLoop

newtype GenServerId tag Source #

The name/id of a GenServer for logging purposes.

Since: 0.24.0

Constructors

MkGenServerId 
Instances
Eq (GenServerId tag) Source # 
Instance details

Defined in Control.Eff.Concurrent.Protocol.EffectfulServer

Methods

(==) :: GenServerId tag -> GenServerId tag -> Bool #

(/=) :: GenServerId tag -> GenServerId tag -> Bool #

Ord (GenServerId tag) Source # 
Instance details

Defined in Control.Eff.Concurrent.Protocol.EffectfulServer

Methods

compare :: GenServerId tag -> GenServerId tag -> Ordering #

(<) :: GenServerId tag -> GenServerId tag -> Bool #

(<=) :: GenServerId tag -> GenServerId tag -> Bool #

(>) :: GenServerId tag -> GenServerId tag -> Bool #

(>=) :: GenServerId tag -> GenServerId tag -> Bool #

max :: GenServerId tag -> GenServerId tag -> GenServerId tag #

min :: GenServerId tag -> GenServerId tag -> GenServerId tag #

(Typeable k, Typeable tag) => Show (GenServerId tag) Source # 
Instance details

Defined in Control.Eff.Concurrent.Protocol.EffectfulServer

Methods

showsPrec :: Int -> GenServerId tag -> ShowS #

show :: GenServerId tag -> String #

showList :: [GenServerId tag] -> ShowS #

IsString (GenServerId tag) Source # 
Instance details

Defined in Control.Eff.Concurrent.Protocol.EffectfulServer

Methods

fromString :: String -> GenServerId tag #

NFData (GenServerId tag) Source # 
Instance details

Defined in Control.Eff.Concurrent.Protocol.EffectfulServer

Methods

rnf :: GenServerId tag -> () #

genServer :: forall tag eLoop e. (HasCallStack, TangibleGenServer tag eLoop e, Server (GenServer tag eLoop e) (InterruptableProcess e)) => (forall x. GenServerId tag -> Eff eLoop x -> Eff (InterruptableProcess e) x) -> (GenServerId tag -> Event tag -> Eff eLoop ()) -> GenServerId tag -> Init (GenServer tag eLoop e) (InterruptableProcess e) Source #

Create a GenServer.

This requires the callback for Events, a initial Model and a GenServerId.

There must be a GenServerProtocol instance.

This is Haskell, so if this functions is partially applied to some Event callback, you get a function back, that generates Inits from GenServerIds, like a factory

Since: 0.24.0

Re-exports

data RequestOrigin (proto :: Type) reply Source #

Wraps the source ProcessId and a unique identifier for a Call.

Since: 0.15.0

Instances
Eq (RequestOrigin proto reply) Source # 
Instance details

Defined in Control.Eff.Concurrent.Protocol.Request

Methods

(==) :: RequestOrigin proto reply -> RequestOrigin proto reply -> Bool #

(/=) :: RequestOrigin proto reply -> RequestOrigin proto reply -> Bool #

Ord (RequestOrigin proto reply) Source # 
Instance details

Defined in Control.Eff.Concurrent.Protocol.Request

Methods

compare :: RequestOrigin proto reply -> RequestOrigin proto reply -> Ordering #

(<) :: RequestOrigin proto reply -> RequestOrigin proto reply -> Bool #

(<=) :: RequestOrigin proto reply -> RequestOrigin proto reply -> Bool #

(>) :: RequestOrigin proto reply -> RequestOrigin proto reply -> Bool #

(>=) :: RequestOrigin proto reply -> RequestOrigin proto reply -> Bool #

max :: RequestOrigin proto reply -> RequestOrigin proto reply -> RequestOrigin proto reply #

min :: RequestOrigin proto reply -> RequestOrigin proto reply -> RequestOrigin proto reply #

Show (RequestOrigin p r) Source # 
Instance details

Defined in Control.Eff.Concurrent.Protocol.Request

Generic (RequestOrigin proto reply) Source # 
Instance details

Defined in Control.Eff.Concurrent.Protocol.Request

Associated Types

type Rep (RequestOrigin proto reply) :: Type -> Type #

Methods

from :: RequestOrigin proto reply -> Rep (RequestOrigin proto reply) x #

to :: Rep (RequestOrigin proto reply) x -> RequestOrigin proto reply #

NFData (RequestOrigin p r) Source # 
Instance details

Defined in Control.Eff.Concurrent.Protocol.Request

Methods

rnf :: RequestOrigin p r -> () #

type Rep (RequestOrigin proto reply) Source # 
Instance details

Defined in Control.Eff.Concurrent.Protocol.Request

type Rep (RequestOrigin proto reply) = D1 (MetaData "RequestOrigin" "Control.Eff.Concurrent.Protocol.Request" "extensible-effects-concurrent-0.24.2-4i89KX4lrqK4F8mqMzm4qM" False) (C1 (MetaCons "RequestOrigin" PrefixI True) (S1 (MetaSel (Just "_requestOriginPid") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 ProcessId) :*: S1 (MetaSel (Just "_requestOriginCallRef") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Int)))

data Reply protocol reply where Source #

The wrapper around replies to Calls.

Since: 0.15.0

Constructors

Reply 

Fields

Instances
Show r => Show (Reply p r) Source # 
Instance details

Defined in Control.Eff.Concurrent.Protocol.Request

Methods

showsPrec :: Int -> Reply p r -> ShowS #

show :: Reply p r -> String #

showList :: [Reply p r] -> ShowS #

NFData (Reply p r) Source # 
Instance details

Defined in Control.Eff.Concurrent.Protocol.Request

Methods

rnf :: Reply p r -> () #

sendReply :: (SetMember Process (Process q) eff, Member Interrupts eff, Tangible reply, Typeable protocol) => Serializer (Reply protocol reply) -> RequestOrigin protocol reply -> reply -> Eff eff () Source #

Send a Reply to a Call.

The reply will be deeply evaluated to rnf.

To send replies for EmbedProtocol instances use embedReplySerializer.

Since: 0.15.0