Codebase list golang-github-vbauerster-mpb / c5c9c89
store ctx on Bar struct Vladimir Bauer 1 year, 10 months ago
1 changed file(s) with 5 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
2121 done chan struct{}
2222 container *Progress
2323 bs *bState
24 ctx context.Context
2425 cancel func()
2526 }
2627
7172 operateState: make(chan func(*bState)),
7273 done: make(chan struct{}),
7374 container: container,
75 ctx: ctx,
7476 cancel: cancel,
7577 }
7678
7779 container.bwg.Add(1)
78 go bar.serve(ctx, bs)
80 go bar.serve(bs)
7981 return bar
8082 }
8183
385387 <-b.done
386388 }
387389
388 func (b *Bar) serve(ctx context.Context, bs *bState) {
390 func (b *Bar) serve(bs *bState) {
389391 defer b.container.bwg.Done()
390392 for {
391393 select {
392394 case op := <-b.operateState:
393395 op(bs)
394 case <-ctx.Done():
396 case <-b.ctx.Done():
395397 bs.aborted = !bs.completed
396398 bs.decoratorShutdownNotify()
397399 b.bs = bs