Module

Pinto.Gen

Package
erl-pinto
Repository
id3as/purescript-erl-pinto

See also 'gen_server' in the OTP docs

#StartLinkBuilder Source

type StartLinkBuilder state msg = { handleInfo :: msg -> state -> HandleInfo state msg, terminate :: Maybe (TerminateReason -> state -> Effect Unit), trapExit :: Maybe (ExitMessage -> msg) }

A typed record containing all the optional extras for configuring a genserver

#stop Source

stop :: forall msg state. ServerName state msg -> Effect Unit

#CallResult Source

data CallResult response state

Constructors

#CastResult Source

#doCall Source

doCall :: forall msg state response. ServerName state msg -> (state -> Call response state msg) -> Effect response

Defines an effectful call that performs an interaction on the state held by the gen server, and perhaps side-effects Directly returns the result of the callback provided


doSomething :: Effect Unit
doSomething = Gen.doCall serverName \state -> pure $ CallResult unit (modifyState state)

See also handle_call and gen_server:call in the OTP docs

#init Source

init :: forall msg state. EffectFn1 Foreign (Tuple2 Atom (StateImpl state msg))

#doCast Source

doCast :: forall msg state. ServerName state msg -> (state -> Cast state msg) -> Effect Unit

Defines an effectful cast that performs an interaction on the state held by the gen server

doSomething :: Effect Unit
doSomething = Gen.cast serverName \state -> pure $ CastNoReply $ modifyState state

See also handle_cast and gen_server:cast in the OTP docs

#defaultHandleInfo Source

defaultHandleInfo :: forall msg state. msg -> state -> HandleInfo state msg

A default implementation of handleInfo that just ignores any messages received A warning will be printed if messages are received

#whereIs Source

whereIs :: forall msg state. ServerName state msg -> Effect (Maybe (Process msg))

Gets the pid of this gen server (if running) This is designed to be called from external agents and therefore might fail, hence the Maybe

#monitor Source

monitor :: forall msg state. ServerName state msg -> (MonitorMsg -> Effect Unit) -> Effect Unit -> Effect (Maybe (RouterRef MonitorRef))

Short cut for monitoring a gen server via Pinto.Monitor

#self Source

self :: forall msg state. StateT (GenContext state msg) Effect (Process msg)

Gets the pid for this gen server

#GenContext Source

newtype GenContext state msg

The context of this gen server (everything except 'state' which tends to get passed into handlers

#StateImpl Source

type StateImpl state msg = { context :: GenContext state msg, innerState :: state }

Internal record used in the actual gen server itself

#GenResultT Source

type GenResultT response state msg = StateT (GenContext state msg) Effect response

The type of any effectful callback into this gen server

#ExitMessage Source

data ExitMessage

The message receives by trapped exits (configured using trapExit)

Constructors

#Call Source

type Call response state msg = GenResultT (CallResult response state) state msg

Type of the callback invoked during a gen_server:handle_call

#Cast Source

type Cast state msg = GenResultT (CastResult state) state msg

Type of the callback invoked during a gen_server:handle_cast

#Init Source

type Init state msg = GenResultT state state msg

Type of the callback invoked during a gen_server:init

#HandleInfo Source

type HandleInfo state msg = GenResultT (CastResult state) state msg

#handle_call Source

handle_call :: forall msg state response. EffectFn3 (StateImpl state msg -> Pid -> Effect (CallResultImpl response state msg)) Pid (StateImpl state msg) (CallResultImpl response state msg)

#handle_info Source

handle_info :: forall msg state. EffectFn2 Foreign (StateImpl state msg) (CastResultImpl state msg)

#terminate Source

terminate :: forall msg state. EffectFn2 Foreign (StateImpl state msg) Atom

#handle_cast Source

handle_cast :: forall msg state. EffectFn2 (StateImpl state msg -> Effect (CastResultImpl state msg)) (StateImpl state msg) (CastResultImpl state msg)

#CallResultImpl Source

data CallResultImpl :: Type -> Type -> Type -> Type

#CastResultImpl Source

#Over Source

type Over state msg = StateT (GenContext state msg) Effect state

Helper type for creating a function that operates in the context of a gen server and operates over 'state' effectfully

#With Source

type With state msg response = StateT (GenContext state msg) Effect response

Helper type for creating a function that operates in the context of a gen server and returns 'response' effectfully

Re-exports from Control.Monad.State

#lift Source

lift :: forall t a m. MonadTrans t => Monad m => m a -> t m a