Codebase list golang-github-vbauerster-mpb / d46b195
pass &wg to decoratorEwmaUpdate Vladimir Bauer 1 year, 10 months ago
1 changed file(s) with 21 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
244244 if current < 0 {
245245 return
246246 }
247 select {
248 case b.operateState <- func(s *bState) {
249 s.decoratorEwmaUpdate(current-s.current, iterDur)
247 result := make(chan *sync.WaitGroup)
248 select {
249 case b.operateState <- func(s *bState) {
250 var wg sync.WaitGroup
251 s.decoratorEwmaUpdate(current-s.current, iterDur, &wg)
250252 s.current = current
251253 if s.triggerComplete && s.current >= s.total {
252254 s.current = s.total
253255 s.completed = true
254256 b.triggerCompletion(s)
255257 }
256 }:
258 result <- &wg
259 }:
260 wg := <-result
261 wg.Wait()
257262 case <-b.ctx.Done():
258263 }
259264 }
296301 // EwmaIncrInt64 increments progress by amount of n and updates EWMA based
297302 // decorators by dur of a single iteration.
298303 func (b *Bar) EwmaIncrInt64(n int64, iterDur time.Duration) {
299 select {
300 case b.operateState <- func(s *bState) {
301 s.decoratorEwmaUpdate(n, iterDur)
304 result := make(chan *sync.WaitGroup)
305 select {
306 case b.operateState <- func(s *bState) {
307 var wg sync.WaitGroup
308 s.decoratorEwmaUpdate(n, iterDur, &wg)
302309 s.current += n
303310 if s.triggerComplete && s.current >= s.total {
304311 s.current = s.total
305312 s.completed = true
306313 b.triggerCompletion(s)
307314 }
308 }:
315 result <- &wg
316 }:
317 wg := <-result
318 wg.Wait()
309319 case <-b.ctx.Done():
310320 }
311321 }
554564 return table
555565 }
556566
557 func (s bState) decoratorEwmaUpdate(n int64, dur time.Duration) {
558 var wg sync.WaitGroup
567 func (s bState) decoratorEwmaUpdate(n int64, dur time.Duration, wg *sync.WaitGroup) {
559568 for i := 0; i < len(s.ewmaDecorators); i++ {
569 wg.Add(1)
560570 switch d := s.ewmaDecorators[i]; i {
561571 case len(s.ewmaDecorators) - 1:
562572 d.EwmaUpdate(n, dur)
573 wg.Done()
563574 default:
564 wg.Add(1)
565575 go func() {
566576 d.EwmaUpdate(n, dur)
567577 wg.Done()
568578 }()
569579 }
570580 }
571 wg.Wait()
572581 }
573582
574583 func (s bState) decoratorAverageAdjust(start time.Time, wg *sync.WaitGroup) {