introduce bool value decor.Statistics.Aborted
address issue #103
Vladimir Bauer
4 years ago
| 25 | 25 | decor.Name(name), |
| 26 | 26 | decor.EwmaETA(decor.ET_STYLE_GO, 60, decor.WCSyncSpace), |
| 27 | 27 | ), |
| 28 | mpb.AppendDecorators(decor.Percentage(decor.WCSyncSpace)), | |
| 28 | mpb.AppendDecorators( | |
| 29 | decor.Any(func(s decor.Statistics) string { | |
| 30 | return fmt.Sprintf("completed: %v", s.Completed) | |
| 31 | }, decor.WCSyncSpaceR), | |
| 32 | decor.Any(func(s decor.Statistics) string { | |
| 33 | return fmt.Sprintf("aborted: %v", s.Aborted) | |
| 34 | }, decor.WCSyncSpaceR), | |
| 35 | decor.OnComplete(decor.Percentage(decor.WCSyncSpace), "done"), | |
| 36 | ), | |
| 29 | 37 | ) |
| 30 | 38 | go func() { |
| 31 | 39 | defer wg.Done() |
| 54 | 54 | trimSpace bool |
| 55 | 55 | completed bool |
| 56 | 56 | completeFlushed bool |
| 57 | aborted bool | |
| 57 | 58 | triggerComplete bool |
| 58 | 59 | dropOnComplete bool |
| 59 | 60 | noPop bool |
| 281 | 282 | close(done) |
| 282 | 283 | return |
| 283 | 284 | } |
| 285 | s.aborted = true | |
| 286 | b.cancel() | |
| 284 | 287 | // container must be run during lifetime of this inner goroutine |
| 285 | 288 | // we control this by done channel declared above |
| 286 | 289 | go func() { |
| 301 | 304 | } |
| 302 | 305 | close(done) // release hold of Abort |
| 303 | 306 | }() |
| 304 | b.cancel() | |
| 305 | 307 | }: |
| 306 | 308 | // guarantee: container is alive during lifetime of this hold |
| 307 | 309 | <-done |
| 531 | 533 | Current: s.current, |
| 532 | 534 | Refill: s.refill, |
| 533 | 535 | Completed: s.completeFlushed, |
| 536 | Aborted: s.aborted, | |
| 534 | 537 | } |
| 535 | 538 | } |
| 536 | 539 | |