-
Notifications
You must be signed in to change notification settings - Fork 178
/
state.go
58 lines (51 loc) · 844 Bytes
/
state.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
package dkg
import (
"fmt"
"sync"
)
// State captures the state of a DKG engine
type State uint32
const (
Init State = iota
Phase1
Phase2
Phase3
End
Shutdown
)
// String returns the string representation of a State
func (s State) String() string {
switch s {
case Init:
return "Init"
case Phase1:
return "Phase1"
case Phase2:
return "Phase2"
case Phase3:
return "Phase3"
case End:
return "End"
case Shutdown:
return "Shutdown"
default:
return fmt.Sprintf("Unknown %d", s)
}
}
// Manager wraps a State with get and set methods
type Manager struct {
sync.Mutex
state State
}
// GetState returns the current state.
func (m *Manager) GetState() State {
m.Lock()
defer m.Unlock()
return m.state
}
// SetState sets the state.
func (m *Manager) SetState(s State) {
m.Lock()
defer m.Unlock()
m.state = s
}