Codebase list golang-github-vbauerster-mpb / 845e8a4
launch each decor interface in new goroutine Vladimir Bauer 1 year, 10 months ago
1 changed file(s) with 12 addition(s) and 27 deletion(s). Raw diff Collapse all Expand all
567567 }
568568
569569 func (s bState) decoratorEwmaUpdate(n int64, dur time.Duration, wg *sync.WaitGroup) {
570 for i := 0; i < len(s.ewmaDecorators); i++ {
570 for _, d := range s.ewmaDecorators {
571571 wg.Add(1)
572 switch d := s.ewmaDecorators[i]; i {
573 case len(s.ewmaDecorators) - 1:
572 d := d
573 go func() {
574574 d.EwmaUpdate(n, dur)
575575 wg.Done()
576 default:
577 go func() {
578 d.EwmaUpdate(n, dur)
579 wg.Done()
580 }()
581 }
576 }()
582577 }
583578 }
584579
585580 func (s bState) decoratorAverageAdjust(start time.Time, wg *sync.WaitGroup) {
586 for i := 0; i < len(s.averageDecorators); i++ {
581 for _, d := range s.averageDecorators {
587582 wg.Add(1)
588 switch d := s.averageDecorators[i]; i {
589 case len(s.averageDecorators) - 1:
583 d := d
584 go func() {
590585 d.AverageAdjust(start)
591586 wg.Done()
592 default:
593 go func() {
594 d.AverageAdjust(start)
595 wg.Done()
596 }()
597 }
587 }()
598588 }
599589 }
600590
601591 func (s bState) decoratorShutdownNotify(wg *sync.WaitGroup) {
602 for i := 0; i < len(s.shutdownListeners); i++ {
592 for _, d := range s.shutdownListeners {
603593 wg.Add(1)
604 switch d := s.shutdownListeners[i]; i {
605 case len(s.shutdownListeners) - 1:
594 d := d
595 go func() {
606596 d.OnShutdown()
607597 wg.Done()
608 default:
609 go func() {
610 d.OnShutdown()
611 wg.Done()
612 }()
613 }
598 }()
614599 }
615600 }
616601