haskell-otp-0.1.0.0: Haskell single-node implementation of Erlang/OTP patterns

Safe HaskellNone
LanguageHaskell2010

Concurrency.OTP.GenServer

Description

Attempt to reproduce Erlang pattern of resource owner process gen_server.

Original documentation: http://www.erlang.org/doc/man/gen_server.html

Synopsis

Documentation

class GenServerState req res s | s -> req, s -> res where Source

Describe GenServer callbacks.

Minimal complete definition

handle_call, handle_cast

Methods

handle_call :: req -> Unique -> GenServerM s req res (CallResult res) Source

Triggered when somebody send request to GenServer by call function. Executed in State monad, and state of GenServer can be changed by implementation. Callback accept request and Unique id of request. Return CallResult (one of: reply, noreply, stop, replyAndStop).

If callback retrun noreply caller process will be blocked until GenServer will explicity call replyWith.

If callback return reply or replyAndStop caller will receive response and continue execution.

If callback retrun stop server will be terminated, onTerminate callback called. Exception ProcessIsDead will be raised in caller process.

handle_cast :: req -> GenServerM s req res CastResult Source

Triggered when somebody send asyncronous command to GenServer by cast function. Executed in State monad, and state of GenServer can be changed by implementation. Callback accept request and return CallResult (one of: noreply, stop). Used for change server state without any response.

onTerminate :: s -> IO () Source

Termination callback executed on GenServer termination. This callback usefull for release resources allocated on server start.

data GenServer req res Source

GenServer handle

data StartStatus req res Source

Returned by start. If start is success - (Ok serverHandle) will be returned, else - Fail.

Constructors

Ok (GenServer req res) 
Fail 

data CallResult res Source

Returned by handle_call callback.

data CastResult Source

Returned by handle_cast callback.

start :: GenServerState req res s => Process (Request req res) s -> IO (StartStatus req res) Source

Start instance of GenServer. Take action for initialization of state. And return StartStatus. If start returns Fail, initialization was failed. In that case onTerminate callback will not be called.

call :: GenServer req res -> req -> IO res Source

Send synchronous request to GenServer. call block caller process until GenServer will reply. If GenServer instance is not alive or will be terminated during call ServerIsDead exception will be raised.

cast :: GenServer req res -> req -> IO () Source

Send asynchronous request to GenServer. cast doesn't block caller thread.

replyWith :: RequestId -> res -> GenServerM s req res () Source

Reply to process, which waits response from server.

reply :: res -> CallResult res Source

noreply :: HandlerResult a => a Source

stop :: HandlerResult a => String -> a Source

callWithTimeout :: GenServer req res -> Maybe Int -> req -> IO (Maybe res) Source

Send synchronous request to GenServer with timeout. call block caller process until GenServer will reply or timeout will be expired. If GenServer instance is not alive or will be terminated during call ServerIsDead exception will be raised. If Timeout will be expired, Nothing will be returned.