genserver

package
v0.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 17, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Call

func Call(self erl.PID, gensrv erl.Dest, request any, timeout time.Duration) (any, error)

func Cast

func Cast(gensrv erl.Dest, request any) error

func Reply

func Reply(client From, reply any)

func SetArg

func SetArg[STATE any](arg any) func(tm TestMsg[STATE]) TestMsg[STATE]

func SetCallProbe

func SetCallProbe[STATE any](probe func(self erl.PID, arg any, from From, state STATE) (call CallResult[STATE], err error)) func(tm TestMsg[STATE]) TestMsg[STATE]

func SetContinueInitProbe added in v0.8.0

func SetContinueInitProbe[STATE any](probe func(self erl.PID, state STATE) (newState STATE, continuation any, err error)) func(ts TestServer[STATE]) TestServer[STATE]

func SetContinueProbe

func SetContinueProbe[STATE any](probe func(self erl.PID, state STATE) (newState STATE, continuation any, err error)) func(tm TestMsg[STATE]) TestMsg[STATE]

func SetInitProbe

func SetInitProbe[STATE any](probe func(self erl.PID, args any) (STATE, any, error)) func(ts TestServer[STATE]) TestServer[STATE]

func SetInitialState

func SetInitialState[STATE any](state STATE) func(ts TestServer[STATE]) TestServer[STATE]

func SetProbe

func SetProbe[STATE any](probe func(self erl.PID, arg any, state STATE) (cont any, newState STATE, err error)) func(tm TestMsg[STATE]) TestMsg[STATE]

func SetTermProbe

func SetTermProbe[STATE any](probe func(self erl.PID, reason error, state STATE)) func(ts TestServer[STATE]) TestServer[STATE]

func SetTestReceiver

func SetTestReceiver[STATE any](tr erl.PID) func(ts TestServer[STATE]) TestServer[STATE]

func Start

func Start[STATE any](self erl.PID, callbackStruct GenServer[STATE], args any, opts ...StartOpt) (erl.PID, error)

The [self] PID is required because the GenServer will notify it when [Init] is completed and will also call [Terminate] if the parent exits and the GenServer is trapping exits.

func StartLink[STATE any](self erl.PID, callbackStruct GenServer[STATE], args any, opts ...StartOpt) (erl.PID, error)

see [StartError] for what type of error is returned.

func StartMonitor

func StartMonitor[STATE any](self erl.PID, callbackStruct GenServer[STATE], args any, opts ...StartOpt) (erl.PID, erl.Ref, error)

func Stop

func Stop(self erl.PID, gensrv erl.Dest, opts ...ExitOpt) error

Types

type CallReply added in v0.11.0

type CallReply struct {
	Status CallReturnStatus
	Term   any
}

This is an intermediate response when invoking Call. Included here since it will appear in process inboxes and so needs to be matched in erl.TestReceiver

type CallRequest added in v0.11.0

type CallRequest struct {
	From From
	Msg  any
}

intermediate message sent to GenServerS from Call. Not normally seen unless the receiver process in Call is not a GenServer

type CallResult

type CallResult[STATE any] struct {
	// if true, then no reply will be sent to the caller. The genserver should reply with [genserver.Reply]
	// at a later time, otherwise the caller will time out.
	NoReply bool
	// The reply that will be sent to the caller
	Msg any
	// The updated state of the GenServer
	State STATE
	// if not nil, will call [HandleContinue] immmediately after [HandleCall] returns with this as the [continuation]
	Continue any
}

type CallReturnStatus added in v0.11.0

type CallReturnStatus string
const (
	OK          CallReturnStatus = "ok"
	NoProc      CallReturnStatus = "noproc"
	Timeout     CallReturnStatus = "timeout"
	CallingSelf CallReturnStatus = "calling_self"
	// supervisor stopped the GenServer
	Shutdown CallReturnStatus = "shutdown"
	// genserver returned [Stop] without a reply. There may be a reason
	Stopped CallReturnStatus = "normal_shutdown"
	// unhandled error happened.
	Other CallReturnStatus = "other"
)

type CastRequest added in v0.11.0

type CastRequest struct {
	Msg any
}

intermediate message sent to GenServerS from Cast. Not normally seen unless the receiver process in Cast is not a GenServer

type CastResult

type CastResult[STATE any] struct {
	State    STATE
	Continue any
}

type ExitOpt

type ExitOpt func(opts exitOptS) exitOptS

func StopReason

func StopReason(e *exitreason.S) ExitOpt

func StopTimeout

func StopTimeout(tout time.Duration) ExitOpt

type From

type From struct {
	// contains filtered or unexported fields
}

type GenServer

type GenServer[STATE any] interface {
	Init(self erl.PID, args any) (InitResult[STATE], error)
	HandleCall(self erl.PID, request any, from From, state STATE) (CallResult[STATE], error)
	HandleCast(self erl.PID, request any, state STATE) (CastResult[STATE], error)
	HandleInfo(self erl.PID, msg any, state STATE) (InfoResult[STATE], error)
	// Handles Continuation terms from other callbacks. Set the [continueTerm] to re-enter the [HandleContinue]
	// callback with a new state
	HandleContinue(self erl.PID, continuation any, state STATE) (newState STATE, continueTerm any, err error)
	Terminate(self erl.PID, reason error, state STATE)
}

type GenServerS

type GenServerS[STATE any] struct {
	// contains filtered or unexported fields
}

func (*GenServerS[STATE]) Receive

func (gs *GenServerS[STATE]) Receive(self erl.PID, inbox <-chan any) error

type InfoResult

type InfoResult[STATE any] struct {
	State    STATE
	Continue any
}

type InitResult

type InitResult[STATE any] struct {
	State    STATE
	Continue any
}

type StartOpt

type StartOpt func(opts StartOpts) StartOpts

func InheritOpts added in v0.6.0

func InheritOpts(o StartOpts) StartOpt

func SetName

func SetName(name erl.Name) StartOpt

type StartOpts added in v0.6.0

type StartOpts interface {
	SetName(erl.Name)
	GetName() erl.Name
	SetStartTimeout(time.Duration)
	GetStartTimeout() time.Duration
}

func DefaultOpts added in v0.7.0

func DefaultOpts() StartOpts

type TestMsg

type TestMsg[STATE any] struct {
	// probe can be used to inject functionality, reply back in cast requests, etc.
	Probe         func(self erl.PID, arg any, state STATE) (cont any, newState STATE, err error)
	CallProbe     func(self erl.PID, arg any, from From, state STATE) (call CallResult[STATE], err error)
	ContinueProbe func(self erl.PID, state STATE) (newState STATE, continuation any, err error)
	Arg           any
}

func NewTestMsg

func NewTestMsg[STATE any](opts ...func(tm TestMsg[STATE]) TestMsg[STATE]) TestMsg[STATE]

type TestNotifCall

type TestNotifCall[STATE any] struct {
	Self    erl.PID
	Result  CallResult[STATE]
	Request TestMsg[STATE]
	Error   error
}

type TestNotifCast

type TestNotifCast[STATE any] struct {
	Self    erl.PID
	State   STATE
	Request TestMsg[STATE]
	Error   error
}

type TestNotifContinue

type TestNotifContinue[STATE any] struct {
	Self    erl.PID
	State   STATE
	Request TestMsg[STATE]
	Error   error
}

type TestNotifInfo

type TestNotifInfo[STATE any] struct {
	Self    erl.PID
	State   STATE
	Request TestMsg[STATE]
	Error   error
}

type TestNotifInit

type TestNotifInit[STATE any] struct {
	Self  erl.PID
	State STATE
	Args  any
	Error error
}

type TestNotifTerminate

type TestNotifTerminate[STATE any] struct {
	Self   erl.PID
	State  STATE
	Reason error
}

type TestServer

type TestServer[STATE any] struct {
	TermProbe     func(self erl.PID, reason error, state STATE)
	InitProbe     func(self erl.PID, args any) (STATE, any, error)
	ContinueProbe func(self erl.PID, state STATE) (newState STATE, continuation any, err error)
	InitialState  STATE
	TestReceiver  erl.PID
}

func NewTestServer

func NewTestServer[STATE any](opts ...func(ts TestServer[STATE]) TestServer[STATE]) TestServer[STATE]

func (TestServer[STATE]) HandleCall

func (ts TestServer[STATE]) HandleCall(self erl.PID, request any, from From, state STATE) (CallResult[STATE], error)

func (TestServer[STATE]) HandleCast

func (ts TestServer[STATE]) HandleCast(self erl.PID, request any, state STATE) (CastResult[STATE], error)

func (TestServer[STATE]) HandleContinue

func (ts TestServer[STATE]) HandleContinue(self erl.PID, continuation any, state STATE) (STATE, any, error)

func (TestServer[STATE]) HandleInfo

func (ts TestServer[STATE]) HandleInfo(self erl.PID, request any, state STATE) (InfoResult[STATE], error)

func (TestServer[STATE]) Init

func (ts TestServer[STATE]) Init(self erl.PID, args any) (InitResult[STATE], error)

func (TestServer[STATE]) Terminate

func (ts TestServer[STATE]) Terminate(self erl.PID, reason error, state STATE)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL