Codebase list golang-github-vbauerster-mpb / 6a1013c
make sure Abort is holding untill inner goroutine finishes Vladimir Bauer 4 years ago
1 changed file(s) with 14 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
267267 // if bar is already in complete state. If drop is true bar will be
268268 // removed as well.
269269 func (b *Bar) Abort(drop bool) {
270 done := make(chan struct{})
270271 select {
271272 case b.operateState <- func(s *bState) {
272273 if s.completed == true {
274 close(done)
273275 return
274276 }
275 if drop {
276 go b.container.dropBar(b)
277 } else {
278 go func() {
277 // container must be run during lifetime of this inner goroutine
278 // we control this by done channel declared above
279 go func() {
280 if drop {
281 b.container.dropBar(b)
282 } else {
279283 var uncompleted int
280284 b.container.traverseBars(func(bar *Bar) bool {
281285 if b != bar && !bar.Completed() {
285289 return true
286290 })
287291 if uncompleted == 0 {
288 select {
289 case b.container.refreshCh <- time.Now():
290 case <-b.container.done:
291 }
292 b.container.refreshCh <- time.Now()
292293 }
293 }()
294 }
294 }
295 close(done) // release hold of Abort
296 }()
295297 b.cancel()
296298 }:
297 <-b.done
299 // guarantee: container is alive during lifetime of this hold
300 <-done
298301 case <-b.done:
299302 }
300303 }