Codebase list golang-github-vbauerster-mpb / b223763
SetTotal waits for b.done if triggering complete event Vladimir Bauer 4 years ago
1 changed file(s) with 13 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
186186 }
187187
188188 // SetTotal sets total to an arbitrary value. It's effective only for
189 // bar which was constructed with `total <= 0`. Setting total to negative
190 // value is equivalent to (*Bar).SetTotal((*Bar).Current(), bool).
191 // If triggerCompleteNow is true then total value is set to current
192 // and complete event is triggered right away.
189 // bar which was constructed with `total <= 0` and if
190 // (*Bar).EnableTriggerComplete hasn't been called yet. Setting total
191 // to negative value is equivalent to (*Bar).SetTotal((*Bar).Current(),
192 // bool). If triggerCompleteNow is true then total value is set to
193 // current and complete event is triggered right away.
193194 func (b *Bar) SetTotal(total int64, triggerCompleteNow bool) {
194 select {
195 case b.operateState <- func(s *bState) {
195 triggerComplete := make(chan bool, 1)
196 select {
197 case b.operateState <- func(s *bState) {
198 triggerComplete <- s.triggerComplete
196199 if s.triggerComplete {
197200 return
198201 }
208211 }
209212 }:
210213 if triggerCompleteNow {
211 <-b.done
214 triggerComplete := <-triggerComplete
215 if !triggerComplete {
216 <-b.done
217 }
212218 }
213219 case <-b.done:
214220 }