| 35 | 35 |
priority int
|
| 36 | 36 |
index int
|
| 37 | 37 |
|
| 38 | |
runningBar *Bar
|
| 39 | |
cacheState *bState
|
| 40 | |
operateState chan func(*bState)
|
| 41 | |
bFrameCh chan *bFrame
|
| 42 | |
syncTableCh chan [][]chan int
|
| 43 | |
intValue chan int64
|
| 44 | |
completed chan bool
|
|
38 |
runningBar *Bar
|
|
39 |
cacheState *bState
|
|
40 |
operateState chan func(*bState)
|
|
41 |
bFrameCh chan *bFrame
|
|
42 |
syncTableCh chan [][]chan int
|
|
43 |
completed chan bool
|
|
44 |
forceRefreshCh chan time.Time
|
| 45 | 45 |
|
| 46 | 46 |
// done is closed by Bar's goroutine, after cacheState is written
|
| 47 | 47 |
done chan struct{}
|
|
| 90 | 90 |
func newBar(
|
| 91 | 91 |
ctx context.Context,
|
| 92 | 92 |
wg *sync.WaitGroup,
|
|
93 |
forceRefreshCh chan time.Time,
|
| 93 | 94 |
filler Filler,
|
| 94 | 95 |
id, width int,
|
| 95 | 96 |
total int64,
|
|
| 121 | 122 |
}
|
| 122 | 123 |
|
| 123 | 124 |
b := &Bar{
|
| 124 | |
priority: s.priority,
|
| 125 | |
runningBar: s.runningBar,
|
| 126 | |
operateState: make(chan func(*bState)),
|
| 127 | |
bFrameCh: make(chan *bFrame, 1),
|
| 128 | |
syncTableCh: make(chan [][]chan int),
|
| 129 | |
intValue: make(chan int64),
|
| 130 | |
completed: make(chan bool),
|
| 131 | |
done: make(chan struct{}),
|
| 132 | |
shutdown: make(chan struct{}),
|
|
125 |
priority: s.priority,
|
|
126 |
runningBar: s.runningBar,
|
|
127 |
operateState: make(chan func(*bState)),
|
|
128 |
bFrameCh: make(chan *bFrame, 1),
|
|
129 |
syncTableCh: make(chan [][]chan int),
|
|
130 |
completed: make(chan bool),
|
|
131 |
done: make(chan struct{}),
|
|
132 |
shutdown: make(chan struct{}),
|
|
133 |
forceRefreshCh: forceRefreshCh,
|
| 133 | 134 |
}
|
| 134 | 135 |
|
| 135 | 136 |
if b.runningBar != nil {
|
|
| 170 | 171 |
|
| 171 | 172 |
// ID returs id of the bar.
|
| 172 | 173 |
func (b *Bar) ID() int {
|
| 173 | |
select {
|
| 174 | |
case b.operateState <- func(s *bState) { b.intValue <- int64(s.id) }:
|
| 175 | |
return int(<-b.intValue)
|
|
174 |
result := make(chan int)
|
|
175 |
select {
|
|
176 |
case b.operateState <- func(s *bState) { result <- s.id }:
|
|
177 |
return <-result
|
| 176 | 178 |
case <-b.done:
|
| 177 | 179 |
return b.cacheState.id
|
| 178 | 180 |
}
|
|
| 180 | 182 |
|
| 181 | 183 |
// Current returns bar's current number, in other words sum of all increments.
|
| 182 | 184 |
func (b *Bar) Current() int64 {
|
| 183 | |
select {
|
| 184 | |
case b.operateState <- func(s *bState) { b.intValue <- s.current }:
|
| 185 | |
return <-b.intValue
|
|
185 |
result := make(chan int64)
|
|
186 |
select {
|
|
187 |
case b.operateState <- func(s *bState) { result <- s.current }:
|
|
188 |
return <-result
|
| 186 | 189 |
case <-b.done:
|
| 187 | 190 |
return b.cacheState.current
|
| 188 | 191 |
}
|
|
| 208 | 211 |
if final {
|
| 209 | 212 |
s.current = s.total
|
| 210 | 213 |
s.toComplete = true
|
|
214 |
go b.forceRefresh()
|
| 211 | 215 |
}
|
| 212 | 216 |
}:
|
| 213 | 217 |
return true
|
|
| 245 | 249 |
if s.current >= s.total {
|
| 246 | 250 |
s.current = s.total
|
| 247 | 251 |
s.toComplete = true
|
|
252 |
go b.forceRefresh()
|
| 248 | 253 |
}
|
| 249 | 254 |
for _, ar := range s.amountReceivers {
|
| 250 | 255 |
ar.NextAmount(n, wdd...)
|
|
| 405 | 410 |
return table
|
| 406 | 411 |
}
|
| 407 | 412 |
|
|
413 |
func (b *Bar) forceRefresh() {
|
|
414 |
select {
|
|
415 |
case b.forceRefreshCh <- time.Now():
|
|
416 |
case <-b.shutdown:
|
|
417 |
}
|
|
418 |
}
|
|
419 |
|
| 408 | 420 |
func newStatistics(s *bState) *decor.Statistics {
|
| 409 | 421 |
return &decor.Statistics{
|
| 410 | 422 |
ID: s.id,
|