Pinto.Gen
- Package
- erl-pinto
- Repository
- id3as/purescript-erl-pinto
See also 'gen_server' in the OTP docs
#startLink Source
startLink :: forall msg state. ServerName state msg -> Init state msg -> Effect StartLinkResult
Starts a typed gen-server proxy with the supplied ServerName, with the state being the result of the supplied effect This sets up the most basic gen server without a terminate handler, handle_info handler or any means of trapping exits
serverName :: ServerName State Unit
serverName = ServerName "some_uuid"
startLink :: Effect StartLinkResult
startLink = Gen.startLink serverName init
init :: Effect State
init = pure {}
See also: gen_server:start_link in the OTP docs (roughly)
#buildStartLink Source
buildStartLink :: forall msg state. ServerName state msg -> Init state msg -> StartLinkBuilder state msg -> Effect StartLinkResult
Starts a typed gen-server proxy with the supplied ServerName, with the state being the result of the supplied effect This takes in a builder of optional values which can be overriden (See: StartLinkBuilder)
serverName :: ServerName State Msg
serverName = ServerName "some_uuid"
startLink :: Effect StartLinkResult
startLink = Gen.startLink serverName init $ Gen.defaultStartLink { handleInfo: myHandleInfo }
init :: Effect State
init = pure {}
handleInfo :: Msg -> State -> Effect (CastResult State)
handleInfo msg state = pure $ CastNoReply state
See also: gen_server:start_link in the OTP docs (roughly)
#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
#defaultStartLink Source
defaultStartLink :: forall msg state. StartLinkBuilder state msg
Creates the default start link options for a gen server These can be replaced by modifying the record
#CallResult Source
data CallResult response state
Constructors
CallReply response state
CallReplyHibernate response state
CallStop TerminateReason response state
#CastResult Source
data CastResult state
Constructors
CastNoReply state
CastNoReplyHibernate state
CastStop state
CastStopReason TerminateReason state
#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
#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
#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)
#handle_cast Source
handle_cast :: forall msg state. EffectFn2 (StateImpl state msg -> Effect (CastResultImpl state msg)) (StateImpl state msg) (CastResultImpl state msg)
#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