launch each decor interface in new goroutine
Vladimir Bauer
1 year, 10 months ago
| 567 | 567 | } |
| 568 | 568 | |
| 569 | 569 | 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 { | |
| 571 | 571 | wg.Add(1) |
| 572 | switch d := s.ewmaDecorators[i]; i { | |
| 573 | case len(s.ewmaDecorators) - 1: | |
| 572 | d := d | |
| 573 | go func() { | |
| 574 | 574 | d.EwmaUpdate(n, dur) |
| 575 | 575 | wg.Done() |
| 576 | default: | |
| 577 | go func() { | |
| 578 | d.EwmaUpdate(n, dur) | |
| 579 | wg.Done() | |
| 580 | }() | |
| 581 | } | |
| 576 | }() | |
| 582 | 577 | } |
| 583 | 578 | } |
| 584 | 579 | |
| 585 | 580 | 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 { | |
| 587 | 582 | wg.Add(1) |
| 588 | switch d := s.averageDecorators[i]; i { | |
| 589 | case len(s.averageDecorators) - 1: | |
| 583 | d := d | |
| 584 | go func() { | |
| 590 | 585 | d.AverageAdjust(start) |
| 591 | 586 | wg.Done() |
| 592 | default: | |
| 593 | go func() { | |
| 594 | d.AverageAdjust(start) | |
| 595 | wg.Done() | |
| 596 | }() | |
| 597 | } | |
| 587 | }() | |
| 598 | 588 | } |
| 599 | 589 | } |
| 600 | 590 | |
| 601 | 591 | func (s bState) decoratorShutdownNotify(wg *sync.WaitGroup) { |
| 602 | for i := 0; i < len(s.shutdownListeners); i++ { | |
| 592 | for _, d := range s.shutdownListeners { | |
| 603 | 593 | wg.Add(1) |
| 604 | switch d := s.shutdownListeners[i]; i { | |
| 605 | case len(s.shutdownListeners) - 1: | |
| 594 | d := d | |
| 595 | go func() { | |
| 606 | 596 | d.OnShutdown() |
| 607 | 597 | wg.Done() |
| 608 | default: | |
| 609 | go func() { | |
| 610 | d.OnShutdown() | |
| 611 | wg.Done() | |
| 612 | }() | |
| 613 | } | |
| 598 | }() | |
| 614 | 599 | } |
| 615 | 600 | } |
| 616 | 601 |