Codebase list golang-github-vbauerster-mpb / c2f3f0f
Cancel case, doesn't quit p.server Vladimir Bauer 9 years ago
2 changed file(s) with 7 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
8181 }
8282
8383 // WithCancel cancellation via channel.
84 // You have to call p.Stop() anyway, after cancel.
8485 // Pancis, if nil channel is passed.
8586 func (p *Progress) WithCancel(ch <-chan struct{}) *Progress {
8687 if ch == nil {
235236 func (p *Progress) server(conf pConf) {
236237
237238 defer func() {
238 conf.ticker.Stop()
239 conf.cw.Flush()
240239 p.conf = conf
241240 if conf.shutdownNotifier != nil {
242241 close(conf.shutdownNotifier)
256255 case op := <-p.ops:
257256 op(&conf)
258257 case <-conf.ticker.C:
259 var notick bool
260 select {
261 // stop ticking if cancel requested
262 case <-conf.cancel:
263 conf.ticker.Stop()
264 notick = true
265 default:
266 }
267
268258 numBars := len(conf.bars)
269 if notick || numBars == 0 {
259 if numBars == 0 {
270260 break
271261 }
272262
301291 for _, b := range conf.bars {
302292 b.flushed()
303293 }
294 case <-conf.cancel:
295 conf.ticker.Stop()
296 conf.cancel = nil
304297 case <-p.stopReqCh:
298 conf.ticker.Stop()
305299 return
306300 }
307301 }
44 import "context"
55
66 // WithContext cancellation via context.
7 // You have to call p.Stop() anyway, after cancel.
78 // Pancis, if nil context is passed
89 func (p *Progress) WithContext(ctx context.Context) *Progress {
910 if ctx == nil {