gstatemachines

package
v1.1.15 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrConditionExpressionResultTypeUnmatch = errors.New("gstatemachines: expression result type must be bool")
View Source
var ErrStateEmptySource = errors.New("gstatemachines: state source invalid")
View Source
var ErrStateEmptyTarget = errors.New("gstatemachines: state target invalid or actions is empty")
View Source
var ErrStateInvalid = errors.New("gstatemachines: state invalid")
View Source
var ErrStateNotExist = errors.New("gstatemachines: state not exist")
View Source
var ErrStateSkip = errors.New("gstatemachines: state skip")
View Source
var ErrTransitionAllNotSatisfied = errors.New("gstatemachines: transition all not satisfied")

Functions

This section is empty.

Types

type BizStater added in v1.1.10

type BizStater interface {
	// Entry 进入状态时执行
	Entry(ctx context.Context, event Event, args ...interface{}) error
	// Exit 退出状态时执行
	Exit(ctx context.Context, event Event, args ...interface{}) error
}

type Event

type Event map[string]interface{}

type State

type State struct {
	BizStater
	Id          string
	Desc        string
	Transitions []*Transition
	// contains filtered or unexported fields
}

func (*State) String

func (s *State) String() string

func (*State) Transform

func (s *State) Transform(ctx context.Context, event Event, args ...interface{}) (*State, error)

type StateDSL

type StateDSL struct {
	Id      string `xml:"id,attr"`
	Desc    string `xml:",innerxml"`
	IsStart bool   `xml:"isStart,attr"`
	IsEnd   bool   `xml:"isEnd,attr"`
}

type StateMachine

type StateMachine struct {
	Definition *StateMachineDefinition
	// contains filtered or unexported fields
}

func (*StateMachine) CurState

func (sm *StateMachine) CurState() *State

func (*StateMachine) Execute

func (sm *StateMachine) Execute(ctx context.Context, sourceStateId string,
	event Event, args ...interface{}) error

type StateMachineDSL

type StateMachineDSL struct {
	XMLName     xml.Name             `xml:"stateMachine"`
	Name        string               `xml:"name,attr"`
	Version     string               `xml:"version,attr"`
	States      []StateDSL           `xml:"states>state"`
	Transitions []StateTransitionDSL `xml:"transitions>transition"`
}

type StateMachineDefinition

type StateMachineDefinition struct {
	Name         string
	Version      string
	StartStateId string
	Id2State     map[string]*State
	Transitions  []*Transition
}

func ToStateMachineDefinition

func ToStateMachineDefinition(dsl string, id2BaseState map[string]BizStater) (*StateMachineDefinition, error)

func (StateMachineDefinition) PlainUML added in v1.0.9

func (d StateMachineDefinition) PlainUML() string

type StateTransitionDSL added in v1.0.9

type StateTransitionDSL struct {
	Desc      string `xml:",innerxml"`
	SourceId  string `xml:"sourceId,attr"`
	Condition string `xml:"condition,attr"`
	TargetId  string `xml:"targetId,attr"`
	Actions   string `xml:"actions,attr"`
}

type Transition

type Transition struct {
	Source     *State
	Condition  string
	Target     *State
	ActionsRaw string
	Actions    []reflect.Value
}

func (*Transition) Satisfied

func (t *Transition) Satisfied(event Event) (bool, error)

Satisfied event 为变量池 condition 为表达式

Jump to

Keyboard shortcuts

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