Codebase list golang-github-vbauerster-mpb / 8a331ab
fix panic: close of closed channel Vladimir Bauer 9 years ago
1 changed file(s) with 4 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
170170 func (p *Progress) Stop() {
171171 p.wg.Wait()
172172 if !p.isDone() {
173 close(p.done)
174173 close(p.operationCh)
175174 }
176175 }
186185
187186 // server monitors underlying channels and renders any progress bars
188187 func (p *Progress) server(cw *cwriter.Writer, t *time.Ticker) {
188 defer func() {
189 t.Stop()
190 close(p.done)
191 }()
189192 const numDrawers = 4
190193 bars := make([]*Bar, 0, 4)
191194 for {
195198 cw = cwriter.New(w)
196199 case op, ok := <-p.operationCh:
197200 if !ok {
198 t.Stop()
199201 return
200202 }
201203 switch op.kind {
257259 t.Stop()
258260 t = time.NewTicker(d)
259261 case <-p.ctx.Done():
260 t.Stop()
261 close(p.done)
262262 return
263263 }
264264 }