kk_state_machine

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseState

type BaseState[T any] struct {
	Transitions map[string]func(T) State[T]
}

BaseState 提供了状态机状态的默认实现

func (*BaseState[T]) Enter

func (s *BaseState[T]) Enter(data T)

func (*BaseState[T]) Exit

func (s *BaseState[T]) Exit(data T)

func (*BaseState[T]) Handle

func (s *BaseState[T]) Handle(event string, data T) (State[T], bool)

type RunningState

type RunningState[T any] struct {
	*BaseState[T]
}

RunningState 是状态机的另一个状态

func NewRunningState

func NewRunningState[T any]() *RunningState[T]

type StartState

type StartState[T any] struct {
	*BaseState[T]
}

StartState 是状态机的一个具体状态

func NewStartState

func NewStartState[T any]() *StartState[T]

type State

type State[T any] interface {
	Enter(data T)
	Exit(data T)
	Handle(event string, data T) (State[T], bool)
}

State 接口定义了状态的基本行为

type StateMachine

type StateMachine[T any] struct {
	CurrentState State[T]
	Data         T
}

StateMachine 实现了状态机

func NewStateMachine

func NewStateMachine[T any](initialState State[T], data T) *StateMachine[T]

func (*StateMachine[T]) Transition

func (sm *StateMachine[T]) Transition(event string)

type StoppedState

type StoppedState[T any] struct {
	*BaseState[T]
}

StoppedState 是状态机的另一个状态

func NewStoppedState

func NewStoppedState[T any]() *StoppedState[T]

Jump to

Keyboard shortcuts

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