run each OnShutdown from within b.serve
Vladimir Bauer
1 year, 10 months ago
| 400 | 400 | case op := <-b.operateState: |
| 401 | 401 | op(bs) |
| 402 | 402 | case <-b.ctx.Done(): |
| 403 | shutdownListeners := bs.shutdownListeners | |
| 403 | 404 | bs.aborted = !bs.completed() |
| 404 | bs.decoratorShutdownNotify(&b.container.bwg) | |
| 405 | 405 | b.bs = bs |
| 406 | 406 | close(b.bsOk) |
| 407 | for _, d := range shutdownListeners { | |
| 408 | d.OnShutdown() | |
| 409 | } | |
| 407 | 410 | b.container.bwg.Done() |
| 408 | 411 | return |
| 409 | 412 | } |
| 587 | 590 | } |
| 588 | 591 | } |
| 589 | 592 | |
| 590 | func (s bState) decoratorShutdownNotify(wg *sync.WaitGroup) { | |
| 591 | wg.Add(len(s.shutdownListeners)) | |
| 592 | for _, d := range s.shutdownListeners { | |
| 593 | d := d | |
| 594 | go func() { | |
| 595 | d.OnShutdown() | |
| 596 | wg.Done() | |
| 597 | }() | |
| 598 | } | |
| 599 | } | |
| 600 | ||
| 601 | 593 | func (s bState) newStatistics(tw int) decor.Statistics { |
| 602 | 594 | return decor.Statistics{ |
| 603 | 595 | AvailableWidth: tw, |