Documentation ¶
Index ¶
- type FSM
- func (slf *FSM[State, Data]) Change(state State)
- func (slf *FSM[State, Data]) Current() (state State)
- func (slf *FSM[State, Data]) GetData() Data
- func (slf *FSM[State, Data]) HasState(state State) bool
- func (slf *FSM[State, Data]) IsZero() bool
- func (slf *FSM[State, Data]) PrevIsZero() bool
- func (slf *FSM[State, Data]) Register(state State, options ...Option[State, Data])
- func (slf *FSM[State, Data]) Unregister(state State)
- func (slf *FSM[State, Data]) Update()
- type Option
- func WithEnterAfterEvent[State comparable, Data any](fn func(state *FSM[State, Data])) Option[State, Data]
- func WithEnterBeforeEvent[State comparable, Data any](fn func(state *FSM[State, Data])) Option[State, Data]
- func WithExitAfterEvent[State comparable, Data any](fn func(state *FSM[State, Data])) Option[State, Data]
- func WithExitBeforeEvent[State comparable, Data any](fn func(state *FSM[State, Data])) Option[State, Data]
- func WithUpdateEvent[State comparable, Data any](fn func(state *FSM[State, Data])) Option[State, Data]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FSM ¶
type FSM[State comparable, Data any] struct { // contains filtered or unexported fields }
FSM 状态机
func (*FSM[State, Data]) Change ¶
func (slf *FSM[State, Data]) Change(state State)
Change 改变状态机状态到新的状态
func (*FSM[State, Data]) Current ¶
func (slf *FSM[State, Data]) Current() (state State)
Current 获取当前状态
func (*FSM[State, Data]) PrevIsZero ¶
PrevIsZero 检查状态机上一个状态是否无状态
func (*FSM[State, Data]) Unregister ¶
func (slf *FSM[State, Data]) Unregister(state State)
Unregister 反注册状态
type Option ¶
type Option[State comparable, Data any] func(fsm *FSM[State, Data], state State)
func WithEnterAfterEvent ¶
func WithEnterAfterEvent[State comparable, Data any](fn func(state *FSM[State, Data])) Option[State, Data]
WithEnterAfterEvent 设置状态进入后的回调
func WithEnterBeforeEvent ¶
func WithEnterBeforeEvent[State comparable, Data any](fn func(state *FSM[State, Data])) Option[State, Data]
WithEnterBeforeEvent 设置状态进入前的回调
- 在首次设置状态时,状态机本身的当前状态为零值状态
func WithExitAfterEvent ¶
func WithExitAfterEvent[State comparable, Data any](fn func(state *FSM[State, Data])) Option[State, Data]
WithExitAfterEvent 设置状态退出后的回调
- 该阶段状态机的状态为新的状态,而非退出前的状态
func WithExitBeforeEvent ¶
func WithExitBeforeEvent[State comparable, Data any](fn func(state *FSM[State, Data])) Option[State, Data]
WithExitBeforeEvent 设置状态退出前的回调
- 该阶段状态机的状态为退出前的状态,而非新的状态
func WithUpdateEvent ¶
func WithUpdateEvent[State comparable, Data any](fn func(state *FSM[State, Data])) Option[State, Data]
WithUpdateEvent 设置状态内刷新的回调
Click to show internal directories.
Click to hide internal directories.