| 22 | 22 |
|
| 23 | 23 |
const (
|
| 24 | 24 |
cmdId = 1 << iota
|
| 25 | |
cmdTotal
|
| 26 | 25 |
cmdCurrent
|
| 27 | 26 |
cmdALen
|
| 28 | 27 |
cmdPLen
|
|
| 41 | 40 |
runningBar *Bar
|
| 42 | 41 |
cacheState *bState
|
| 43 | 42 |
operateState chan func(*bState)
|
| 44 | |
cmdValue chan int64
|
|
43 |
cmdValue chan int
|
| 45 | 44 |
frameReaderCh chan io.Reader
|
| 46 | 45 |
|
| 47 | 46 |
// done is closed by Bar's goroutine, after cacheState is written
|
|
| 116 | 115 |
priority: s.priority,
|
| 117 | 116 |
runningBar: s.runningBar,
|
| 118 | 117 |
operateState: make(chan func(*bState)),
|
| 119 | |
cmdValue: make(chan int64),
|
|
118 |
cmdValue: make(chan int),
|
| 120 | 119 |
frameReaderCh: make(chan io.Reader, 1),
|
| 121 | 120 |
done: make(chan struct{}),
|
| 122 | 121 |
shutdown: make(chan struct{}),
|
|
| 159 | 158 |
func (b *Bar) NumOfAppenders() int {
|
| 160 | 159 |
select {
|
| 161 | 160 |
case b.cmdValue <- cmdALen:
|
| 162 | |
return int(<-b.cmdValue)
|
|
161 |
return <-b.cmdValue
|
| 163 | 162 |
case <-b.done:
|
| 164 | 163 |
return len(b.cacheState.aDecorators)
|
| 165 | 164 |
}
|
|
| 169 | 168 |
func (b *Bar) NumOfPrependers() int {
|
| 170 | 169 |
select {
|
| 171 | 170 |
case b.cmdValue <- cmdPLen:
|
| 172 | |
return int(<-b.cmdValue)
|
|
171 |
return <-b.cmdValue
|
| 173 | 172 |
case <-b.done:
|
| 174 | 173 |
return len(b.cacheState.pDecorators)
|
| 175 | 174 |
}
|
|
| 179 | 178 |
func (b *Bar) ID() int {
|
| 180 | 179 |
select {
|
| 181 | 180 |
case b.cmdValue <- cmdId:
|
| 182 | |
return int(<-b.cmdValue)
|
|
181 |
return <-b.cmdValue
|
| 183 | 182 |
case <-b.done:
|
| 184 | 183 |
return b.cacheState.id
|
| 185 | 184 |
}
|
|
| 189 | 188 |
func (b *Bar) Current() int64 {
|
| 190 | 189 |
select {
|
| 191 | 190 |
case b.cmdValue <- cmdCurrent:
|
| 192 | |
return <-b.cmdValue
|
|
191 |
return int64(<-b.cmdValue)
|
| 193 | 192 |
case <-b.done:
|
| 194 | 193 |
return b.cacheState.current
|
| 195 | |
}
|
| 196 | |
}
|
| 197 | |
|
| 198 | |
// Total returns bar's total number.
|
| 199 | |
func (b *Bar) Total() int64 {
|
| 200 | |
select {
|
| 201 | |
case b.cmdValue <- cmdTotal:
|
| 202 | |
return <-b.cmdValue
|
| 203 | |
case <-b.done:
|
| 204 | |
return b.cacheState.total
|
| 205 | 194 |
}
|
| 206 | 195 |
}
|
| 207 | 196 |
|
|
| 272 | 261 |
case cmd := <-b.cmdValue:
|
| 273 | 262 |
switch {
|
| 274 | 263 |
case cmd&cmdId != 0:
|
| 275 | |
b.cmdValue <- int64(s.id)
|
| 276 | |
case cmd&cmdTotal != 0:
|
| 277 | |
b.cmdValue <- s.total
|
|
264 |
b.cmdValue <- s.id
|
| 278 | 265 |
case cmd&cmdCurrent != 0:
|
| 279 | |
b.cmdValue <- s.current
|
|
266 |
b.cmdValue <- int(s.current)
|
| 280 | 267 |
case cmd&cmdPLen != 0:
|
| 281 | |
b.cmdValue <- int64(len(s.pDecorators))
|
|
268 |
b.cmdValue <- len(s.pDecorators)
|
| 282 | 269 |
case cmd&cmdALen != 0:
|
| 283 | |
b.cmdValue <- int64(len(s.aDecorators))
|
|
270 |
b.cmdValue <- len(s.aDecorators)
|
| 284 | 271 |
case cmd&cmdCompleted != 0:
|
| 285 | |
var v int64
|
|
272 |
var v int
|
| 286 | 273 |
if s.toComplete {
|
| 287 | 274 |
v = 1
|
| 288 | 275 |
}
|