Cancel case, doesn't quit p.server
Vladimir Bauer
9 years ago
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | // WithCancel cancellation via channel. |
| 84 | // You have to call p.Stop() anyway, after cancel. | |
| 84 | 85 | // Pancis, if nil channel is passed. |
| 85 | 86 | func (p *Progress) WithCancel(ch <-chan struct{}) *Progress { |
| 86 | 87 | if ch == nil { |
| 235 | 236 | func (p *Progress) server(conf pConf) { |
| 236 | 237 | |
| 237 | 238 | defer func() { |
| 238 | conf.ticker.Stop() | |
| 239 | conf.cw.Flush() | |
| 240 | 239 | p.conf = conf |
| 241 | 240 | if conf.shutdownNotifier != nil { |
| 242 | 241 | close(conf.shutdownNotifier) |
| 256 | 255 | case op := <-p.ops: |
| 257 | 256 | op(&conf) |
| 258 | 257 | 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 | ||
| 268 | 258 | numBars := len(conf.bars) |
| 269 | if notick || numBars == 0 { | |
| 259 | if numBars == 0 { | |
| 270 | 260 | break |
| 271 | 261 | } |
| 272 | 262 | |
| 301 | 291 | for _, b := range conf.bars { |
| 302 | 292 | b.flushed() |
| 303 | 293 | } |
| 294 | case <-conf.cancel: | |
| 295 | conf.ticker.Stop() | |
| 296 | conf.cancel = nil | |
| 304 | 297 | case <-p.stopReqCh: |
| 298 | conf.ticker.Stop() | |
| 305 | 299 | return |
| 306 | 300 | } |
| 307 | 301 | } |