pass container.bwg to decoratorShutdownNotify
Vladimir Bauer
1 year, 10 months ago
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | func (b *Bar) serve(bs *bState) { |
| 386 | defer b.container.bwg.Done() | |
| 387 | 386 | for { |
| 388 | 387 | select { |
| 389 | 388 | case op := <-b.operateState: |
| 390 | 389 | op(bs) |
| 391 | 390 | case <-b.ctx.Done(): |
| 392 | 391 | bs.aborted = !bs.completed |
| 393 | bs.decoratorShutdownNotify() | |
| 392 | bs.decoratorShutdownNotify(&b.container.bwg) | |
| 394 | 393 | b.bs = bs |
| 395 | 394 | close(b.bsOk) |
| 395 | b.container.bwg.Done() | |
| 396 | 396 | return |
| 397 | 397 | } |
| 398 | 398 | } |
| 581 | 581 | wg.Wait() |
| 582 | 582 | } |
| 583 | 583 | |
| 584 | func (s bState) decoratorShutdownNotify() { | |
| 585 | var wg sync.WaitGroup | |
| 584 | func (s bState) decoratorShutdownNotify(wg *sync.WaitGroup) { | |
| 586 | 585 | for i := 0; i < len(s.shutdownListeners); i++ { |
| 586 | wg.Add(1) | |
| 587 | 587 | switch d := s.shutdownListeners[i]; i { |
| 588 | 588 | case len(s.shutdownListeners) - 1: |
| 589 | 589 | d.OnShutdown() |
| 590 | wg.Done() | |
| 590 | 591 | default: |
| 591 | wg.Add(1) | |
| 592 | 592 | go func() { |
| 593 | 593 | d.OnShutdown() |
| 594 | 594 | wg.Done() |
| 595 | 595 | }() |
| 596 | 596 | } |
| 597 | 597 | } |
| 598 | wg.Wait() | |
| 599 | 598 | } |
| 600 | 599 | |
| 601 | 600 | func newStatistics(tw int, s *bState) decor.Statistics { |