Module

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

Instances

#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

#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

Instances

#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

Instances

#From Source

newtype From reply

#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 callback
  • result is the result of any operation within a ResultT context

Instances

#Context Source

newtype Context cont stop msg state

#Action Source

data Action cont stop

An action to be returned to OTP See {shutdown, reason}, {timeout...} etc in the gen_server documentation This should be constructed and returned with the xxWithAction methods inside GenServer callbacks

Constructors

#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

#call Source

call :: forall reply cont stop msg state. ServerRef cont stop msg state -> CallFn reply cont stop msg state -> Effect reply

#cast Source

cast :: forall cont stop msg state. ServerRef cont stop msg state -> CastFn cont stop msg state -> Effect Unit

#stop Source

stop :: forall cont stop msg state. ServerRef cont stop msg state -> Effect Unit

#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

#replyTo Source

replyTo :: forall reply. From reply -> reply -> Effect Unit

#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

#NativeCallResult Source

data NativeCallResult :: Type -> Type -> Type -> Type -> Type

Instances

#NativeReturnResult Source

data NativeReturnResult :: Type -> Type -> Type -> Type

Instances

Re-exports from Effect.Class

#liftEffect Source

liftEffect :: forall m a. MonadEffect m => Effect a -> m a

Re-exports from Pinto.Types

#ExitMessage Source

data ExitMessage

Constructors