-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfsm.go
More file actions
50 lines (43 loc) · 984 Bytes
/
Copy pathfsm.go
File metadata and controls
50 lines (43 loc) · 984 Bytes
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
package processor
import "sync/atomic"
// ProcessorState represents the current state of a processor in its lifecycle
type ProcessorState int32
const (
StateCreated ProcessorState = iota
StateInitializing
StateWaitingToStart
StateRunning
StatePaused
StateTerminating
StateTerminated
)
// String returns a human-readable representation of the processor state
func (s ProcessorState) String() string {
switch s {
case StateCreated:
return "Created"
case StateInitializing:
return "Initializing"
case StateWaitingToStart:
return "WaitingToStart"
case StateRunning:
return "Running"
case StatePaused:
return "Paused"
case StateTerminating:
return "Terminating"
case StateTerminated:
return "Terminated"
default:
return "Unknown"
}
}
type fsm struct {
state atomic.Int32
}
func (fsm *fsm) getState() ProcessorState {
return ProcessorState(fsm.state.Load())
}
func (fsm *fsm) setState(newState ProcessorState) {
fsm.state.Store(int32(newState))
}