Codebase list golang-github-vbauerster-mpb / abc4e39
refactoring internal types Vladimir Bauer 7 years ago
1 changed file(s) with 10 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
3636 runningBar *Bar
3737 cacheState *bState
3838 operateState chan func(*bState)
39 int64Ch chan int64
40 boolCh chan bool
4139 bFrameCh chan *bFrame
4240 syncTableCh chan [][]chan int
41 intValue chan int64
42 completed chan bool
4343
4444 // done is closed by Bar's goroutine, after cacheState is written
4545 done chan struct{}
118118 priority: s.priority,
119119 runningBar: s.runningBar,
120120 operateState: make(chan func(*bState)),
121 int64Ch: make(chan int64),
122 boolCh: make(chan bool),
123121 bFrameCh: make(chan *bFrame, 1),
124122 syncTableCh: make(chan [][]chan int),
123 intValue: make(chan int64),
124 completed: make(chan bool),
125125 done: make(chan struct{}),
126126 shutdown: make(chan struct{}),
127127 }
165165 // ID returs id of the bar.
166166 func (b *Bar) ID() int {
167167 select {
168 case b.operateState <- func(s *bState) { b.int64Ch <- int64(s.id) }:
169 return int(<-b.int64Ch)
168 case b.operateState <- func(s *bState) { b.intValue <- int64(s.id) }:
169 return int(<-b.intValue)
170170 case <-b.done:
171171 return b.cacheState.id
172172 }
175175 // Current returns bar's current number, in other words sum of all increments.
176176 func (b *Bar) Current() int64 {
177177 select {
178 case b.operateState <- func(s *bState) { b.int64Ch <- s.current }:
179 return <-b.int64Ch
178 case b.operateState <- func(s *bState) { b.intValue <- s.current }:
179 return <-b.intValue
180180 case <-b.done:
181181 return b.cacheState.current
182182 }
240240 // condition, like for !bar.Completed() {...} so when toComplete=true
241241 // it is called once (at which time, the bar is still alive), then
242242 // quits the loop and never suppose to be called afterwards.
243 return <-b.boolCh
243 return <-b.completed
244244 }
245245
246246 func (b *Bar) wSyncTable() [][]chan int {
259259 select {
260260 case op := <-b.operateState:
261261 op(s)
262 case b.boolCh <- s.toComplete:
262 case b.completed <- s.toComplete:
263263 case <-cancel:
264264 s.toComplete = true
265265 cancel = nil