machine/model.go
Matthew Rich 85e39191b8
Some checks failed
Lint / golangci-lint (push) Failing after 9m53s
Machine Tests / test (push) Successful in 40s
fix lint errors
2024-04-04 13:08:50 -07:00

32 lines
584 B
Go

// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
package machine
type Modeler interface {
Trigger(transition Transitioner) error
ChangeState(target State) State
InspectState() State
}
type Model struct {
state State
}
func NewModel(initial State) Modeler {
return &Model{state: initial}
}
func (m *Model) Trigger(transition Transitioner) error {
return transition.Run(m)
}
func (m *Model) ChangeState(target State) State {
oldState := m.state
m.state = target
return oldState
}
func (m *Model) InspectState() State {
return m.state
}