Documentation
¶
Overview ¶
Package states provides reusable state definitions.
- basic - connected - disposed
Index ¶
- Variables
- func AddErrConnecting(event *am.Event, mach *am.Machine, err error, args am.A) error
- type BasicStatesDef
- type ConnPoolGroupsDef
- type ConnPoolState
- type ConnPoolStatesDef
- type ConnectedGroupsDef
- type ConnectedState
- type ConnectedStatesDef
- type DisposedGroupsDef
- type DisposedHandlers
- type DisposedStatesDef
Constants ¶
This section is empty.
Variables ¶
var ( // ConnectedStates contains all the states for the Connected state schema. ConnectedStates = ssC // ConnectedGroups contains all the state groups for the Connected state // schema. ConnectedGroups = sgC )
var ( // ConnPoolStates contains all the states for the ConnPool state schema. ConnPoolStates = ssPc // ConnPoolGroups contains all the state groups for the ConnPool state schema. ConnPoolGroups = sgCp )
var ( // DisposedStates contains all the states for the Disposed machine. DisposedStates = ssD // DisposedGroups contains all the state groups for the Disposed machine. DisposedGroups = sgD )
var BasicSchema = am.Schema{ ssB.Exception: {Multi: true}, ssB.ErrNetwork: { Multi: true, Add: S{Exception}, Require: S{Exception}, }, ssB.ErrHandlerTimeout: { Multi: true, Add: S{Exception}, Require: S{Exception}, }, ssB.Start: {}, ssB.Ready: {Require: S{ssB.Start}}, ssB.Healthcheck: {Multi: true}, ssB.Heartbeat: {}, }
var (
// BasicStates contains all the states for the Basic machine.
BasicStates = ssB
)
var ConnPoolSchema = am.Schema{
ssPc.ErrConnecting: {Require: S{Exception}},
ssPc.Disconnected: {
Remove: S{ssPc.Connecting, ssPc.ConnectedFully, ssPc.Disconnecting},
},
ssPc.Connecting: {
Require: S{Start},
Remove: S{ssPc.Disconnecting},
},
ssPc.Connected: {
Require: S{Start},
Remove: S{ssPc.Disconnected},
},
ssPc.ConnectedFully: {
Require: S{ssPc.Connected},
Remove: S{ssPc.Disconnected},
},
ssPc.Disconnecting: {
Remove: S{ssPc.ConnectedFully, ssPc.Connected, ssPc.Connecting},
},
}
ConnPoolSchema represents all relations and properties of ConnPoolStates.
var ConnectedSchema = am.Schema{ ssC.ErrConnecting: {Require: S{Exception}}, ssC.Connecting: { Require: S{Start}, Remove: sgC.Connected, }, ssC.Connected: { Require: S{Start}, Remove: sgC.Connected, }, ssC.Disconnecting: {Remove: sgC.Connected}, ssC.Disconnected: { Auto: true, Remove: sgC.Connected, }, }
ConnectedSchema represents all relations and properties of ConnectedStates.
var DisposedArgHandler = "DisposedArgHandler"
DisposedArgHandler is the key for the disposal handler passed to the RegisterDisposal state. It needs to contain the EXPLICIT type of am.HandlerDispose, eg
var dispose am.HandlerDispose = func(id string, ctx *am.StateCtx) {
// ...
}
var DisposedSchema = am.Schema{ ssD.RegisterDisposal: {Multi: true}, ssD.Disposing: {Remove: S{Start}}, ssD.Disposed: {Remove: S{ssD.Disposing, Start}}, }
DisposedSchema represents all relations and properties of DisposedStates.
var ErrConnecting = errors.New("error connecting")
var StatesUtilsFile string
Functions ¶
Types ¶
type BasicStatesDef ¶ added in v0.8.0
type BasicStatesDef struct {
*am.StatesBase
// ErrNetwork indicates a generic network error.
ErrNetwork string
// ErrHandlerTimeout indicates one of the state machine handlers has timed
// out.
ErrHandlerTimeout string
// Start indicates the machine should be working. Removing start can force
// stop the machine.
Start string
// Ready indicates the machine meets criteria to perform work.
Ready string
// Healthcheck is a periodic request making sure that the machine is still
// alive.
Healthcheck string
// Heartbeat is a periodic state that ensures the integrity of the machine.
Heartbeat string
}
BasicStatesDef contains all the basic states.
type ConnPoolGroupsDef ¶ added in v0.10.3
type ConnPoolGroupsDef struct {
Connected S
}
ConnPoolGroupsDef contains all the state groups of the ConnPool state schema.
type ConnPoolState ¶ added in v0.10.3
type ConnPoolState = string
type ConnPoolStatesDef ¶ added in v0.10.3
type ConnPoolStatesDef struct {
// ErrConnecting is a detailed connection error, eg no access.
ErrConnecting ConnPoolState
Connecting ConnPoolState
Connected ConnPoolState
ConnectedFully ConnPoolState
Disconnecting ConnPoolState
Disconnected ConnPoolState
*am.StatesBase
}
ConnPoolStatesDef contains states for a connection status. Required states: - Start
type ConnectedGroupsDef ¶ added in v0.8.0
type ConnectedGroupsDef struct {
Connected S
}
ConnectedGroupsDef contains all the state groups of the Connected state schema.
type ConnectedState ¶ added in v0.10.3
type ConnectedState = string
type ConnectedStatesDef ¶ added in v0.8.0
type ConnectedStatesDef struct {
// ErrConnecting is a detailed connection error, eg no access.
ErrConnecting ConnectedState
Connecting ConnectedState
Connected ConnectedState
Disconnecting ConnectedState
Disconnected ConnectedState
*am.StatesBase
}
ConnectedStatesDef contains states for a connection status. Required states: - Start
type DisposedGroupsDef ¶ added in v0.10.0
type DisposedGroupsDef struct{}
DisposedGroupsDef contains all the state groups Disposed state machine.
type DisposedHandlers ¶ added in v0.10.0
type DisposedHandlers struct {
// DisposedHandlers is a list of handler for pkg/states.DisposedStates
DisposedHandlers []am.HandlerDispose
}
DisposedHandlers handle disposal and NEEDS to be initialized manually.
h := &Handlers{
DisposedHandlers: &ssam.DisposedHandlers{},
}
func (*DisposedHandlers) DisposedState ¶ added in v0.17.0
func (h *DisposedHandlers) DisposedState(e *am.Event)
func (*DisposedHandlers) DisposingState ¶ added in v0.10.0
func (h *DisposedHandlers) DisposingState(e *am.Event)
func (*DisposedHandlers) RegisterDisposalEnter ¶ added in v0.10.0
func (h *DisposedHandlers) RegisterDisposalEnter(e *am.Event) bool
func (*DisposedHandlers) RegisterDisposalState ¶ added in v0.10.0
func (h *DisposedHandlers) RegisterDisposalState(e *am.Event)
RegisterDisposalState registers an external / dynamic disposal handler. Machine handlers should overload DisposingState and call super instead.
type DisposedStatesDef ¶ added in v0.10.0
type DisposedStatesDef struct {
*am.StatesBase
// RegisterDisposal registers a disposal handler passed under the
// DisposedArgHandler key. Requires [DisposedHandlers] to be bound prior to
// the registration. Handlers registered via RegisterDisposal can block.
RegisterDisposal string
// Disposing starts the machine disposal - first state-based and then calls
// [am.Machine.Dispose].
Disposing string
// Disposed indicates that the machine has disposed allocated resources
// and is ready to be garbage collected by calling [am.Machine.Dispose].
Disposed string
}
DisposedStatesDef contains all the states of the Disposed state machine. One a machine implements this state mixing, it HAS TO be disposed using the Disposing state (instead of am.Machine.Dispose).
Required states: - Start