Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module contains a mechanism to specify what kind of messages (aka
requests) a Server
(Process
) can handle, and if the caller blocks and
waits for an answer, which the server process provides.
The type magic in the Api
type familiy allows to define a related set of requests along
with the corresponding responses.
Request handling can be either blocking, if a response is requred, or non-blocking.
A process can serve a specific Api
instance by using the functions provided by
the Control.Eff.Concurrent.Api.Server module.
To enable a process to use such a service, the functions provided by the Control.Eff.Concurrent.Api.Client should be used.
Synopsis
- data family Api (api :: Type) (reply :: Synchronicity)
- data Synchronicity
- newtype Server api = Server {}
- fromServer :: forall api api. Iso (Server api) (Server api) ProcessId ProcessId
- proxyAsServer :: proxy api -> ProcessId -> Server api
- asServer :: forall api. ProcessId -> Server api
Documentation
data family Api (api :: Type) (reply :: Synchronicity) Source #
This data family defines an API, a communication interface description between at least two processes. The processes act as servers or client(s) regarding a specific instance of this type.
The first parameter is usually a user defined phantom type that identifies
the Api
instance.
The second parameter specifies if a specific constructor of an (GADT-like)
Api
instance is Synchronous
, i.e. returns a result and blocks the caller
or if it is Asynchronous
Example:
data BookShop deriving Typeable data instance Api BookShop r where RentBook :: BookId -> Api BookShop ('Synchronous (Either RentalError RentalId)) BringBack :: RentalId -> Api BookShop 'Asynchronous type BookId = Int type RentalId = Int type RentalError = String
Instances
Show (Observation o) => Show (Api (CallbackObserver o) r) # | |
Defined in Control.Eff.Concurrent.Api.Observer | |
data Api (CallbackObserver o) r Source # | |
Defined in Control.Eff.Concurrent.Api.Observer |
data Synchronicity Source #
The (promoted) constructors of this type specify (at the type level) the
reply behavior of a specific constructor of an Api
instance.
Synchronous Type | Specify that handling a request is a blocking operation
with a specific return type, e.g. |
Asynchronous | Non-blocking, asynchronous, request handling |
Instances
Eq (Server api) Source # | |
Ord (Server api) Source # | |
Defined in Control.Eff.Concurrent.Api | |
Read (Server api) Source # | |
Typeable api => Show (Server api) Source # | |
proxyAsServer :: proxy api -> ProcessId -> Server api Source #