Safe Haskell | None |
---|---|
Language | Haskell2010 |
Functions to implement Api
servers.
Synopsis
- serve :: forall a effScheduler. (Servable a, SetMember Process (Process effScheduler) (ServerEff a), Member Interrupts (ServerEff a), HasCallStack) => SchedulerProxy effScheduler -> a -> Eff (ServerEff a) ()
- spawnServer :: forall a effScheduler eff. (Servable a, ServerEff a ~ InterruptableProcess effScheduler, SetMember Process (Process effScheduler) eff, Member Interrupts eff, HasCallStack) => SchedulerProxy effScheduler -> a -> Eff eff (ServerPids a)
- spawnServerWithEffects :: forall a effScheduler eff. (Servable a, SetMember Process (Process effScheduler) (ServerEff a), SetMember Process (Process effScheduler) eff, Member Interrupts eff, Member Interrupts (ServerEff a), HasCallStack) => SchedulerProxy effScheduler -> a -> (Eff (ServerEff a) () -> Eff (InterruptableProcess effScheduler) ()) -> Eff eff (ServerPids a)
- data ApiHandler api eff where
- ApiHandler :: {..} -> ApiHandler api eff
- castCallback :: forall api eff. Lens' (ApiHandler api eff) (Maybe (Api api Asynchronous -> Eff eff ApiServerCmd))
- callCallback :: forall api eff reply. Getter (ApiHandler api eff) (Maybe (Api api (Synchronous reply) -> (reply -> Eff eff ()) -> Eff eff ApiServerCmd))
- terminateCallback :: forall api eff. Lens' (ApiHandler api eff) (Maybe (ExitReason Recoverable -> Eff eff ()))
- apiHandler :: (Api api Asynchronous -> Eff e ApiServerCmd) -> (forall r. Api api (Synchronous r) -> (r -> Eff e ()) -> Eff e ApiServerCmd) -> (ExitReason Recoverable -> Eff e ()) -> ApiHandler api e
- apiHandlerForever :: (Api api Asynchronous -> Eff e ()) -> (forall r. Api api (Synchronous r) -> (r -> Eff e ()) -> Eff e ()) -> (ExitReason Recoverable -> Eff e ()) -> ApiHandler api e
- castHandler :: (Api api Asynchronous -> Eff eff ApiServerCmd) -> ApiHandler api eff
- castHandlerForever :: (Api api Asynchronous -> Eff eff ()) -> ApiHandler api eff
- callHandler :: (forall r. Api api (Synchronous r) -> (r -> Eff e ()) -> Eff e ApiServerCmd) -> ApiHandler api e
- callHandlerForever :: (forall r. Api api (Synchronous r) -> (r -> Eff e ()) -> Eff e ()) -> ApiHandler api e
- castAndCallHandler :: (Api api Asynchronous -> Eff e ApiServerCmd) -> (forall r. Api api (Synchronous r) -> (r -> Eff e ()) -> Eff e ApiServerCmd) -> ApiHandler api e
- castAndCallHandlerForever :: (Api api Asynchronous -> Eff e ()) -> (forall r. Api api (Synchronous r) -> (r -> Eff e ()) -> Eff e ()) -> ApiHandler api e
- data ApiServerCmd where
- unhandledCallError :: forall p x r q. (Typeable p, HasCallStack, SetMember Process (Process q) r, Member Interrupts r) => SchedulerProxy q -> Api p (Synchronous x) -> (x -> Eff r ()) -> Eff r ApiServerCmd
- unhandledCastError :: forall p r q. (Typeable p, HasCallStack, SetMember Process (Process q) r, Member Interrupts r) => SchedulerProxy q -> Api p Asynchronous -> Eff r ApiServerCmd
- defaultTermination :: forall q r. (HasCallStack, SetMember Process (Process q) r, Member (Logs LogMessage) r) => SchedulerProxy q -> ExitReason Recoverable -> Eff r ()
- class Servable a where
- type ServerEff a :: [Type -> Type]
- type ServerPids a
- toServerPids :: proxy a -> ProcessId -> ServerPids a
- toServerCallback :: (Member Interrupts (ServerEff a), SetMember Process (Process effScheduler) (ServerEff a)) => SchedulerProxy effScheduler -> a -> ServerCallback (ServerEff a)
- data ServerCallback eff = ServerCallback {
- _requestHandlerSelector :: MessageSelector (Eff eff ApiServerCmd)
- _terminationHandler :: ExitReason Recoverable -> Eff eff ()
- requestHandlerSelector :: forall eff. Lens' (ServerCallback eff) (MessageSelector (Eff eff ApiServerCmd))
- terminationHandler :: forall eff. Lens' (ServerCallback eff) (ExitReason Recoverable -> Eff eff ())
Api Server
serve :: forall a effScheduler. (Servable a, SetMember Process (Process effScheduler) (ServerEff a), Member Interrupts (ServerEff a), HasCallStack) => SchedulerProxy effScheduler -> a -> Eff (ServerEff a) () Source #
Receive and process incoming requests until the process exits.
spawnServer :: forall a effScheduler eff. (Servable a, ServerEff a ~ InterruptableProcess effScheduler, SetMember Process (Process effScheduler) eff, Member Interrupts eff, HasCallStack) => SchedulerProxy effScheduler -> a -> Eff eff (ServerPids a) Source #
Spawn a new process, that will receive and process incoming requests until the process exits.
spawnServerWithEffects :: forall a effScheduler eff. (Servable a, SetMember Process (Process effScheduler) (ServerEff a), SetMember Process (Process effScheduler) eff, Member Interrupts eff, Member Interrupts (ServerEff a), HasCallStack) => SchedulerProxy effScheduler -> a -> (Eff (ServerEff a) () -> Eff (InterruptableProcess effScheduler) ()) -> Eff eff (ServerPids a) Source #
Spawn a new process, that will receive and process incoming requests until the process exits. Also handle all internal effects.
Api Callbacks
data ApiHandler api eff where Source #
A record of callbacks, handling requests sent to a server Process
, all
belonging to a specific Api
family instance.
The values of this type can be serve
ed or combined via Servable
or
ServerCallback
s.
ApiHandler | |
|
Instances
Default (ApiHandler api eff) Source # | |
Defined in Control.Eff.Concurrent.Api.Server def :: ApiHandler api eff # | |
Typeable a => Servable (ApiHandler a eff) Source # | |
Defined in Control.Eff.Concurrent.Api.Server type ServerEff (ApiHandler a eff) :: [Type -> Type] Source # type ServerPids (ApiHandler a eff) :: Type Source # toServerPids :: proxy (ApiHandler a eff) -> ProcessId -> ServerPids (ApiHandler a eff) Source # toServerCallback :: (Member Interrupts (ServerEff (ApiHandler a eff)), SetMember Process (Process effScheduler) (ServerEff (ApiHandler a eff))) => SchedulerProxy effScheduler -> ApiHandler a eff -> ServerCallback (ServerEff (ApiHandler a eff)) Source # | |
type ServerEff (ApiHandler a eff) Source # | |
Defined in Control.Eff.Concurrent.Api.Server | |
type ServerPids (ApiHandler a eff) Source # | |
Defined in Control.Eff.Concurrent.Api.Server |
castCallback :: forall api eff. Lens' (ApiHandler api eff) (Maybe (Api api Asynchronous -> Eff eff ApiServerCmd)) Source #
callCallback :: forall api eff reply. Getter (ApiHandler api eff) (Maybe (Api api (Synchronous reply) -> (reply -> Eff eff ()) -> Eff eff ApiServerCmd)) Source #
terminateCallback :: forall api eff. Lens' (ApiHandler api eff) (Maybe (ExitReason Recoverable -> Eff eff ())) Source #
apiHandler :: (Api api Asynchronous -> Eff e ApiServerCmd) -> (forall r. Api api (Synchronous r) -> (r -> Eff e ()) -> Eff e ApiServerCmd) -> (ExitReason Recoverable -> Eff e ()) -> ApiHandler api e Source #
Create an ApiHandler
with a _castCallback
, a _callCallback
and
a _terminateCallback
implementation.
apiHandlerForever :: (Api api Asynchronous -> Eff e ()) -> (forall r. Api api (Synchronous r) -> (r -> Eff e ()) -> Eff e ()) -> (ExitReason Recoverable -> Eff e ()) -> ApiHandler api e Source #
Like apiHandler
but the server will loop until an error is raised or
the process exits.
The callback actions won't decide wether to stop the
server or not, instead the ApiServerCmd
HandleNextRequest
is used.
castHandler :: (Api api Asynchronous -> Eff eff ApiServerCmd) -> ApiHandler api eff Source #
Create an ApiHandler
with only a _castCallback
implementation.
castHandlerForever :: (Api api Asynchronous -> Eff eff ()) -> ApiHandler api eff Source #
Like castHandler
but the server will loop until an error is raised or
the process exits. See apiHandlerForver
.
callHandler :: (forall r. Api api (Synchronous r) -> (r -> Eff e ()) -> Eff e ApiServerCmd) -> ApiHandler api e Source #
Create an ApiHandler
with only a _callCallback
implementation.
callHandlerForever :: (forall r. Api api (Synchronous r) -> (r -> Eff e ()) -> Eff e ()) -> ApiHandler api e Source #
Like callHandler
but the server will loop until an error is raised or
the process exits. See apiHandlerForver
.
castAndCallHandler :: (Api api Asynchronous -> Eff e ApiServerCmd) -> (forall r. Api api (Synchronous r) -> (r -> Eff e ()) -> Eff e ApiServerCmd) -> ApiHandler api e Source #
Create an ApiHandler
with only a _castCallback
and _callCallback
implementation.
castAndCallHandlerForever :: (Api api Asynchronous -> Eff e ()) -> (forall r. Api api (Synchronous r) -> (r -> Eff e ()) -> Eff e ()) -> ApiHandler api e Source #
Like castAndCallHandler
but the server will loop until an error is raised or
the process exits. See apiHandlerForver
.
data ApiServerCmd where Source #
A command to the server loop started e.g. by server
or spawnServerWithEffects
.
Typically returned by an ApiHandler
member to indicate if the server
should continue or stop.
HandleNextRequest :: ApiServerCmd | Tell the server to keep the server loop running |
StopApiServer :: ExitReason Recoverable -> ApiServerCmd | Tell the server to exit, this will make |
Instances
Show ApiServerCmd Source # | |
Defined in Control.Eff.Concurrent.Api.Server showsPrec :: Int -> ApiServerCmd -> ShowS # show :: ApiServerCmd -> String # showList :: [ApiServerCmd] -> ShowS # | |
Generic ApiServerCmd Source # | |
Defined in Control.Eff.Concurrent.Api.Server type Rep ApiServerCmd :: Type -> Type # from :: ApiServerCmd -> Rep ApiServerCmd x # to :: Rep ApiServerCmd x -> ApiServerCmd # | |
NFData ApiServerCmd Source # | |
Defined in Control.Eff.Concurrent.Api.Server rnf :: ApiServerCmd -> () # | |
type Rep ApiServerCmd Source # | |
Defined in Control.Eff.Concurrent.Api.Server type Rep ApiServerCmd = D1 (MetaData "ApiServerCmd" "Control.Eff.Concurrent.Api.Server" "extensible-effects-concurrent-0.14.3-2A21xUrPb8IFjpFb8UKi9V" False) (C1 (MetaCons "HandleNextRequest" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "StopApiServer" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (ExitReason Recoverable)))) |
unhandledCallError :: forall p x r q. (Typeable p, HasCallStack, SetMember Process (Process q) r, Member Interrupts r) => SchedulerProxy q -> Api p (Synchronous x) -> (x -> Eff r ()) -> Eff r ApiServerCmd Source #
A default handler to use in _callCallback
in ApiHandler
. It will call
raiseError
with a nice error message.
unhandledCastError :: forall p r q. (Typeable p, HasCallStack, SetMember Process (Process q) r, Member Interrupts r) => SchedulerProxy q -> Api p Asynchronous -> Eff r ApiServerCmd Source #
A default handler to use in _castCallback
in ApiHandler
. It will call
raiseError
with a nice error message.
defaultTermination :: forall q r. (HasCallStack, SetMember Process (Process q) r, Member (Logs LogMessage) r) => SchedulerProxy q -> ExitReason Recoverable -> Eff r () Source #
Either do nothing, if the error message is Nothing
,
or call exitWithError
with the error message.
Callback Composition
class Servable a where Source #
Helper type class to allow composition of ApiHandler
.
toServerPids :: proxy a -> ProcessId -> ServerPids a Source #
toServerCallback :: (Member Interrupts (ServerEff a), SetMember Process (Process effScheduler) (ServerEff a)) => SchedulerProxy effScheduler -> a -> ServerCallback (ServerEff a) Source #
Convert the value to a ServerCallback
Instances
data ServerCallback eff Source #
Building block for composition of ApiHandler
.
A wrapper for ApiHandler
. Use this to combine ApiHandler
, allowing a
process to implement several Api
instances. The termination will be evenly
propagated.
Create this via e.g. Servable
instances
To serve multiple apis use <>
to combine server callbacks, e.g.
@@
let f = apiHandlerServerCallback px $ ApiHandler ...
g = apiHandlerServerCallback px $ ApiHandler ...
h = f <> g
in serve px h
@@
ServerCallback | |
|
Instances
requestHandlerSelector :: forall eff. Lens' (ServerCallback eff) (MessageSelector (Eff eff ApiServerCmd)) Source #
terminationHandler :: forall eff. Lens' (ServerCallback eff) (ExitReason Recoverable -> Eff eff ()) Source #