-
Notifications
You must be signed in to change notification settings - Fork 2
/
fsm.go
60 lines (49 loc) · 1.58 KB
/
fsm.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package fsm
// StartState is a constant for defining the slug of
// the start state for all StateMachines.
const StartState = "start"
// StateMachine is an array of all BuildState functions
type StateMachine []BuildState
// StateMap is a k:v map for all BuildState functions
// in a StateMachine. This is exclusively utilized
// by the internal workings of targets.
type StateMap map[string]BuildState
// BuildState is a function that generates a State
// with access to a specific Emitter and Traverser
type BuildState func(Emitter, Traverser) *State
// State represents an individual state in a larger state machine
type State struct {
Slug string
Entry func(isReentry bool) error
ValidIntents func() []*Intent
Transition func(*Intent, map[string]string) *State
}
// Emitter is a generic interface to output arbitrary data.
// Emit is generally called from State.EntryAction.
type Emitter interface {
Emit(interface{}) error
}
// A Store is a generic interface responsible for managing
// The fetching and creation of traversers
type Store interface {
FetchTraverser(uuid string) (Traverser, error)
CreateTraverser(uuid string) (Traverser, error)
}
// A Traverser is an individual that is traversing the
// StateMachine. This interface that is responsible
// for managing the state of that individual
type Traverser interface {
// UUID
UUID() string
SetUUID(string)
// Platform
Platform() string
SetPlatform(string)
// State
CurrentState() string
SetCurrentState(string)
// Data
Upsert(key string, value interface{})
Fetch(key string) interface{}
Delete(key string)
}