Pinto.GenServer
- Package
- erl-pinto
- Repository
- id3as/purescript-erl-pinto
Module representing the gen_server in OTP See also 'gen_server' in the OTP docs (https://erlang.org/doc/man/gen_server.html)
#InitFn Source
type InitFn cont stop msg state = ResultT cont stop msg state (InitResult cont state)
The callback invoked on GenServer startup: see gen_server:init
#InitResult Source
data InitResult cont state
The various return values from an init callback These roughly map onto the tuples in the OTP documentation
Constructors
InitOk state
InitOkTimeout state Int
InitOkContinue state cont
InitOkHibernate state
InitStop Foreign
InitIgnore
Instances
ExportsTo (InitResult cont state) (NativeInitResult state)
#ServerSpec Source
type ServerSpec cont stop msg state = { handleContinue :: Maybe (ContinueFn cont stop msg state), handleInfo :: Maybe (InfoFn cont stop msg state), init :: InitFn cont stop msg state, name :: Maybe (RegistryName (ServerType cont stop msg state)), terminate :: Maybe (TerminateFn cont stop msg state), trapExits :: Maybe (ExitMessage -> msg) }
The configuration passed into startLink in order to start a gen server Everything except the 'init' callback is optional Note: GenServers started without a name will not be callable without some means of retrieving the pid
#ServerType Source
newtype ServerType cont stop msg state
#ServerPid Source
newtype ServerPid cont stop msg state
Instances
HasPid (ServerPid cont stop msg state)
HasProcess msg (ServerPid const stop msg state)
#ServerRef Source
type ServerRef cont stop msg state = RegistryReference (ServerPid cont stop msg state) (ServerType cont stop msg state)
The typed reference of a GenServer, containing all the information required to get hold of an instance
#CallFn Source
type CallFn reply cont stop msg state = From reply -> state -> ResultT cont stop msg state (CallResult reply cont stop state)
The callback invoked within a GenServer.call: see gen_server:call
#CallResult Source
data CallResult reply cont stop state
The result of a GenServer.call (handle_call) action
Constructors
CallResult (Maybe reply) (Maybe (Action cont stop)) state
Instances
Functor (CallResult reply cont stop)
ExportsTo (CallResult reply cont stop outerState) (NativeCallResult reply cont stop outerState)
#CastFn Source
type CastFn cont stop msg state = state -> ResultT cont stop msg state (ReturnResult cont stop state)
The type of the handleCast callback see gen_server:cast
#InfoFn Source
type InfoFn cont stop msg state = msg -> state -> ResultT cont stop msg state (ReturnResult cont stop state)
The type of the handleInfo callback see gen_server:handle_info
#TerminateFn Source
type TerminateFn cont stop msg state = ShutdownReason -> state -> ResultT cont stop msg state Unit
The type of the terminate callback see gen_server:terminate
#ContinueFn Source
type ContinueFn cont stop msg state = cont -> state -> ResultT cont stop msg state (ReturnResult cont stop state)
The type of the handleContinue callback see gen_server:handle_continue
#ReturnResult Source
data ReturnResult cont stop state
The result of a GenServer.handle_info or GenServer.handle_cast callback
Constructors
ReturnResult (Maybe (Action cont stop)) state
Instances
Functor (ReturnResult cont stop)
ExportsTo (ReturnResult cont stop outerState) (NativeReturnResult cont stop outerState)
#ResultT Source
newtype ResultT cont stop msg state result
The reader monad in which all GenServer operations take place
cont
is the type that will be passed into a handle_continue callback, if there is no handleContinue present, this can just be 'Unit'stop
is the data type that can be returned with the StopOther action if StopOther is not being used, then this can simply 'Unit'msg
represents the type of message that this gen server will receive in its handleInfo callback, if no messages are expected, this can simply be 'Unit'state
represents the internal state of this GenServer, created in 'init and then passed into each subsequent callbackresult
is the result of any operation within a ResultT context
Instances
Functor (ResultT cont stop msg state)
Apply (ResultT cont stop msg state)
Applicative (ResultT cont stop msg state)
Bind (ResultT cont stop msg state)
Monad (ResultT cont stop msg state)
MonadEffect (ResultT cont stop msg state)
ReceivesMessage (ResultT cont stop msg state) msg
HasSelf (ResultT cont stop msg state) msg
#defaultSpec Source
defaultSpec :: forall cont stop msg state. InitFn cont stop msg state -> ServerSpec cont stop msg state
Given an InitFn callback, create a default GenServer specification with all of the optionals set to default values This is the preferred method of creating the config passed into GenServer.startLink
#startLink Source
startLink :: forall cont stop msg state. (ServerSpec cont stop msg state) -> Effect (StartLinkResult (ServerPid cont stop msg state))
Given a specification, starts a GenServer
Standard usage:
GenServer.startLink $ GenServer.defaultSpec init
where
init :: InitFn Unit Unit Unit {}
init = pure $ InitOk {}
#reply Source
reply :: forall reply cont stop state. reply -> state -> CallResult reply cont stop state
Creates a result from inside a GenServer 'handle_call' that results in the 'reply' result being sent to the caller and the new state being stored
#replyWithAction Source
replyWithAction :: forall reply cont stop state. reply -> Action cont stop -> state -> CallResult reply cont stop state
Creates a result from inside a GenServer 'handle_call' that results in the 'reply' result being sent to the caller , the new state being stored and the attached action being returned to OTP for processing
#noReply Source
noReply :: forall reply cont stop state. state -> CallResult reply cont stop state
Creates a result from inside a GenServer 'handle_call' that results in the new state being stored and nothing being returned to the caller (yet)
#noReplyWithAction Source
noReplyWithAction :: forall reply cont stop state. Action cont stop -> state -> CallResult reply cont stop state
Creates a result from inside a GenServer 'handle_call' that results in the new state being stored and nothing being returned to the caller (yet) and the attached action being returned to OTP for processing
#return Source
return :: forall cont stop state. state -> ReturnResult cont stop state
Creates a result from inside a GenServer 'handle_info/handle_cast' that results in the new state being stored
#returnWithAction Source
returnWithAction :: forall cont stop state. Action cont stop -> state -> ReturnResult cont stop state
Creates a result from inside a GenServer 'handle_info/handle_cast' that results in the new state being stored and the attached action being returned to OTP for processing
#whereIs Source
whereIs :: forall cont stop msg state. RegistryName (ServerType cont stop msg state) -> Effect (Maybe (Process msg))
Given a RegistryName with a valid (ServerType), get hold of a typed Process msg
to which messages
can be sent (arriving in the handleInfo callback)
#init Source
init :: forall cont state. EffectFn1 (List (Effect (InitResult cont state))) (NativeInitResult state)
#handle_call Source
handle_call :: forall reply cont stop msg state. EffectFn3 (CallFn reply cont stop msg state) (From reply) (OuterState cont stop msg state) (NativeCallResult reply cont stop (OuterState cont stop msg state))
#handle_cast Source
handle_cast :: forall cont stop msg state. EffectFn2 (CastFn cont stop msg state) (OuterState cont stop msg state) (NativeReturnResult cont stop (OuterState cont stop msg state))
#handle_info Source
handle_info :: forall cont stop msg state. EffectFn2 Foreign (OuterState cont stop msg state) (NativeReturnResult cont stop (OuterState cont stop msg state))
#handle_continue Source
handle_continue :: forall cont stop msg state. EffectFn2 cont (OuterState cont stop msg state) (NativeReturnResult cont stop (OuterState cont stop msg state))
#terminate Source
terminate :: forall cont stop msg state. EffectFn2 Foreign (OuterState cont stop msg state) Atom
#NativeInitResult Source
data NativeInitResult :: Type -> Type
Instances
ExportsTo (InitResult cont state) (NativeInitResult state)
#NativeCallResult Source
data NativeCallResult :: Type -> Type -> Type -> Type -> Type
Instances
ExportsTo (CallResult reply cont stop outerState) (NativeCallResult reply cont stop outerState)
#NativeReturnResult Source
data NativeReturnResult :: Type -> Type -> Type -> Type
Instances
ExportsTo (ReturnResult cont stop outerState) (NativeReturnResult cont stop outerState)
Re-exports from Effect.Class
#liftEffect Source
liftEffect :: forall m a. MonadEffect m => Effect a -> m a