cmdValue is chan int64
Vladimir Bauer
7 years ago
| 41 | 41 | runningBar *Bar |
| 42 | 42 | cacheState *bState |
| 43 | 43 | operateState chan func(*bState) |
| 44 | cmdValue chan int | |
| 44 | cmdValue chan int64 | |
| 45 | 45 | frameReaderCh chan io.Reader |
| 46 | 46 | |
| 47 | 47 | // done is closed by Bar's goroutine, after cacheState is written |
| 116 | 116 | priority: s.priority, |
| 117 | 117 | runningBar: s.runningBar, |
| 118 | 118 | operateState: make(chan func(*bState)), |
| 119 | cmdValue: make(chan int), | |
| 119 | cmdValue: make(chan int64), | |
| 120 | 120 | frameReaderCh: make(chan io.Reader, 1), |
| 121 | 121 | done: make(chan struct{}), |
| 122 | 122 | shutdown: make(chan struct{}), |
| 159 | 159 | func (b *Bar) NumOfAppenders() int { |
| 160 | 160 | select { |
| 161 | 161 | case b.cmdValue <- cmdALen: |
| 162 | return <-b.cmdValue | |
| 162 | return int(<-b.cmdValue) | |
| 163 | 163 | case <-b.done: |
| 164 | 164 | return len(b.cacheState.aDecorators) |
| 165 | 165 | } |
| 169 | 169 | func (b *Bar) NumOfPrependers() int { |
| 170 | 170 | select { |
| 171 | 171 | case b.cmdValue <- cmdPLen: |
| 172 | return <-b.cmdValue | |
| 172 | return int(<-b.cmdValue) | |
| 173 | 173 | case <-b.done: |
| 174 | 174 | return len(b.cacheState.pDecorators) |
| 175 | 175 | } |
| 179 | 179 | func (b *Bar) ID() int { |
| 180 | 180 | select { |
| 181 | 181 | case b.cmdValue <- cmdId: |
| 182 | return <-b.cmdValue | |
| 182 | return int(<-b.cmdValue) | |
| 183 | 183 | case <-b.done: |
| 184 | 184 | return b.cacheState.id |
| 185 | 185 | } |
| 189 | 189 | func (b *Bar) Current() int64 { |
| 190 | 190 | select { |
| 191 | 191 | case b.cmdValue <- cmdCurrent: |
| 192 | return int64(<-b.cmdValue) | |
| 192 | return <-b.cmdValue | |
| 193 | 193 | case <-b.done: |
| 194 | 194 | return b.cacheState.current |
| 195 | 195 | } |
| 199 | 199 | func (b *Bar) Total() int64 { |
| 200 | 200 | select { |
| 201 | 201 | case b.cmdValue <- cmdTotal: |
| 202 | return int64(<-b.cmdValue) | |
| 202 | return <-b.cmdValue | |
| 203 | 203 | case <-b.done: |
| 204 | 204 | return b.cacheState.total |
| 205 | 205 | } |
| 272 | 272 | case cmd := <-b.cmdValue: |
| 273 | 273 | switch { |
| 274 | 274 | case cmd&cmdId != 0: |
| 275 | b.cmdValue <- s.id | |
| 275 | b.cmdValue <- int64(s.id) | |
| 276 | 276 | case cmd&cmdTotal != 0: |
| 277 | b.cmdValue <- int(s.total) | |
| 277 | b.cmdValue <- s.total | |
| 278 | 278 | case cmd&cmdCurrent != 0: |
| 279 | b.cmdValue <- int(s.current) | |
| 279 | b.cmdValue <- s.current | |
| 280 | 280 | case cmd&cmdPLen != 0: |
| 281 | b.cmdValue <- len(s.pDecorators) | |
| 281 | b.cmdValue <- int64(len(s.pDecorators)) | |
| 282 | 282 | case cmd&cmdALen != 0: |
| 283 | b.cmdValue <- len(s.aDecorators) | |
| 283 | b.cmdValue <- int64(len(s.aDecorators)) | |
| 284 | 284 | case cmd&cmdCompleted != 0: |
| 285 | var v int | |
| 285 | var v int64 | |
| 286 | 286 | if s.toComplete { |
| 287 | 287 | v = 1 |
| 288 | 288 | } |