Don't wait if there are no bars
Vladimir Bauer
8 years ago
| 110 | 110 |
// RemoveAllPrependers removes all prepend functions
|
| 111 | 111 |
func (b *Bar) RemoveAllPrependers() {
|
| 112 | 112 |
select {
|
| 113 | |
case b.operateState <- func(s *bState) {
|
| 114 | |
s.pDecorators = nil
|
| 115 | |
}:
|
|
113 |
case b.operateState <- func(s *bState) { s.pDecorators = nil }:
|
| 116 | 114 |
case <-b.done:
|
| 117 | 115 |
}
|
| 118 | 116 |
}
|
|
| 120 | 118 |
// RemoveAllAppenders removes all append functions
|
| 121 | 119 |
func (b *Bar) RemoveAllAppenders() {
|
| 122 | 120 |
select {
|
| 123 | |
case b.operateState <- func(s *bState) {
|
| 124 | |
s.aDecorators = nil
|
| 125 | |
}:
|
|
121 |
case b.operateState <- func(s *bState) { s.aDecorators = nil }:
|
| 126 | 122 |
case <-b.done:
|
| 127 | 123 |
}
|
| 128 | 124 |
}
|
|
| 183 | 179 |
return
|
| 184 | 180 |
}
|
| 185 | 181 |
select {
|
| 186 | |
case b.operateState <- func(s *bState) {
|
| 187 | |
s.refill = &refill{r, till}
|
| 188 | |
}:
|
|
182 |
case b.operateState <- func(s *bState) { s.refill = &refill{r, till} }:
|
| 189 | 183 |
case <-b.done:
|
| 190 | 184 |
}
|
| 191 | 185 |
}
|
| 29 | 29 |
pState struct {
|
| 30 | 30 |
bHeap *priorityQueue
|
| 31 | 31 |
heapUpdated bool
|
|
32 |
zeroWait bool
|
| 32 | 33 |
idCounter int
|
| 33 | 34 |
width int
|
| 34 | 35 |
format string
|
|
| 107 | 108 |
// Zero is highest priority, i.e. bar will be on top.
|
| 108 | 109 |
func (p *Progress) UpdateBarPriority(b *Bar, priority int) {
|
| 109 | 110 |
select {
|
| 110 | |
case p.operateState <- func(s *pState) {
|
| 111 | |
s.bHeap.update(b, priority)
|
| 112 | |
}:
|
|
111 |
case p.operateState <- func(s *pState) { s.bHeap.update(b, priority) }:
|
| 113 | 112 |
case <-p.done:
|
| 114 | 113 |
}
|
| 115 | 114 |
}
|
|
| 118 | 117 |
func (p *Progress) BarCount() int {
|
| 119 | 118 |
result := make(chan int, 1)
|
| 120 | 119 |
select {
|
| 121 | |
case p.operateState <- func(s *pState) {
|
| 122 | |
result <- s.bHeap.Len()
|
| 123 | |
}:
|
|
120 |
case p.operateState <- func(s *pState) { result <- s.bHeap.Len() }:
|
| 124 | 121 |
return <-result
|
| 125 | 122 |
case <-p.done:
|
| 126 | 123 |
return 0
|
|
| 131 | 128 |
// It's optional to call, in other words if you don't call Progress.Wait(),
|
| 132 | 129 |
// it's not guaranteed that all bars will be flushed completely to the underlying io.Writer.
|
| 133 | 130 |
func (p *Progress) Wait() {
|
|
131 |
if p.BarCount() == 0 {
|
|
132 |
select {
|
|
133 |
case p.operateState <- func(s *pState) { s.zeroWait = true }:
|
|
134 |
case <-p.done:
|
|
135 |
}
|
|
136 |
return
|
|
137 |
}
|
| 134 | 138 |
<-p.done
|
| 135 | 139 |
}
|
| 136 | 140 |
|