fsm

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Index

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 NewFSM

func NewFSM[State comparable, Data any](data Data) *FSM[State, Data]

NewFSM 创建一个新的状态机

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]) GetData

func (slf *FSM[State, Data]) GetData() Data

GetData 获取状态机数据

func (*FSM[State, Data]) HasState

func (slf *FSM[State, Data]) HasState(state State) bool

HasState 检查状态机是否存在特定状态

func (*FSM[State, Data]) IsZero

func (slf *FSM[State, Data]) IsZero() bool

IsZero 检查状态机是否无状态

func (*FSM[State, Data]) PrevIsZero

func (slf *FSM[State, Data]) PrevIsZero() bool

PrevIsZero 检查状态机上一个状态是否无状态

func (*FSM[State, Data]) Register

func (slf *FSM[State, Data]) Register(state State, options ...Option[State, Data])

Register 注册状态

func (*FSM[State, Data]) Unregister

func (slf *FSM[State, Data]) Unregister(state State)

Unregister 反注册状态

func (*FSM[State, Data]) Update

func (slf *FSM[State, Data]) Update()

Update 触发当前状态

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 设置状态内刷新的回调

Jump to

Keyboard shortcuts

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