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
32package progress
import "sync/atomic"
var _ Stager = (*AtomicStage)(nil)
type AtomicStage struct {
current atomic.Value
}
func (s *AtomicStage) getCurrent() string {
return s.current.Load().(string)
}
func (s *AtomicStage) setCurrent(new string) {
s.current.Store(new)
}
func (s *AtomicStage) Stage() string {
return s.getCurrent()
}
func (s *AtomicStage) Set(new string) {
s.setCurrent(new)
}
func NewAtomicStage(current string) *AtomicStage {
result := AtomicStage{}
result.current.Store(current)
return &result
}