Module

Pinto.GenServer

Module representing the gen_server in OTP See also 'gen_server' in the OTP docs (https://erlang.org/doc/man/gen_server.html)

#InitFn

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

data InitResult cont state

The various return values from an init callback These roughly map onto the tuples in the OTP documentation

Constructors

#ServerSpec

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

newtype ServerType cont stop msg state

#ServerPid

newtype ServerPid cont stop msg state

Instances

#ServerRef

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

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

data CallResult reply cont stop state

The result of a GenServer.call (handle_call) action

Constructors

Instances

#CastFn

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

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

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

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

data ReturnResult cont stop state

The result of a GenServer.handle_info or GenServer.handle_cast callback

Constructors

Instances

#From

newtype From reply

#ResultT

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

newtype Context cont stop msg state

#Action

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

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

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

#cast

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

#stop

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

#reply

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

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

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

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

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

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

replyTo :: forall cont stop msg state reply. From reply -> reply -> ResultT cont stop msg state Unit

#whereIs

whereIs :: forall cont stop msg state. RegistryName (ServerType cont stop msg state) -> Effect (Maybe (ServerPid cont stop msg state))

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

init :: forall cont state. EffectFn1 (List (Effect (InitResult cont state))) (NativeInitResult state)

#handle_call

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

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

handle_info :: forall cont stop msg state. EffectFn2 Foreign (OuterState cont stop msg state) (NativeReturnResult cont stop (OuterState cont stop msg state))

#handle_continue

handle_continue :: forall cont stop msg state. EffectFn2 cont (OuterState cont stop msg state) (NativeReturnResult cont stop (OuterState cont stop msg state))

#terminate

terminate :: forall cont stop msg state. EffectFn2 Foreign (OuterState cont stop msg state) Atom

#NativeInitResult

#NativeCallResult

data NativeCallResult t0 t1 t2 t3

#NativeReturnResult

data NativeReturnResult t0 t1 t2

#exportInitResult

exportInitResult :: forall cont state. InitResult cont state -> NativeInitResult state

#exportCallResult

exportCallResult :: forall reply cont stop outerState. CallResult reply cont stop outerState -> NativeCallResult reply cont stop outerState

#exportReturnResult

exportReturnResult :: forall cont stop outerState. ReturnResult cont stop outerState -> NativeReturnResult cont stop outerState

Re-exports from Effect.Class

#liftEffect

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

Re-exports from Pinto.Types

#ExitMessage

data ExitMessage

Constructors

Modules