refactoring: TestWithContext
Vladimir Bauer
3 years ago
| 98 | 98 | ctx, cancel := context.WithCancel(context.Background()) |
| 99 | 99 | p := mpb.NewWithContext(ctx, mpb.WithShutdownNotifier(shutdown), mpb.WithOutput(io.Discard)) |
| 100 | 100 | |
| 101 | done := make(chan struct{}) | |
| 102 | 101 | bar := p.AddBar(0) // never complete bar |
| 103 | 102 | go func() { |
| 104 | 103 | for !bar.Aborted() { |
| 105 | 104 | time.Sleep(randomDuration(100 * time.Millisecond)) |
| 106 | 105 | cancel() |
| 107 | 106 | } |
| 108 | close(done) | |
| 109 | 107 | }() |
| 110 | 108 | |
| 111 | go func() { | |
| 112 | <-done | |
| 113 | p.Wait() | |
| 114 | }() | |
| 109 | go p.Wait() | |
| 115 | 110 | |
| 116 | 111 | select { |
| 117 | 112 | case <-shutdown: |