make sure b.cancel is called after OnComplete decorators
Vladimir Bauer
3 years ago
| 55 | 55 |
}
|
| 56 | 56 |
|
| 57 | 57 |
type renderFrame struct {
|
| 58 | |
rows []io.Reader
|
| 59 | |
shutdown bool
|
| 60 | |
err error
|
|
58 |
rows []io.Reader
|
|
59 |
shutdown int
|
|
60 |
rmOnComplete bool
|
|
61 |
noPop bool
|
|
62 |
err error
|
| 61 | 63 |
}
|
| 62 | 64 |
|
| 63 | 65 |
func newBar(ctx context.Context, container *Progress, bs *bState) *Bar {
|
|
| 410 | 412 |
}
|
| 411 | 413 |
|
| 412 | 414 |
func (b *Bar) render(tw int) {
|
| 413 | |
var done bool
|
| 414 | 415 |
fn := func(s *bState) {
|
| 415 | 416 |
var rows []io.Reader
|
| 416 | 417 |
stat := newStatistics(tw, s)
|
|
| 427 | 428 |
return
|
| 428 | 429 |
}
|
| 429 | 430 |
}
|
| 430 | |
frame := &renderFrame{rows: rows}
|
|
431 |
frame := &renderFrame{
|
|
432 |
rows: rows,
|
|
433 |
shutdown: s.shutdown,
|
|
434 |
rmOnComplete: s.dropOnComplete,
|
|
435 |
noPop: s.noPop,
|
|
436 |
}
|
| 431 | 437 |
if s.completed || s.aborted {
|
| 432 | |
frame.shutdown = !done || s.shutdown == 1
|
| 433 | |
b.cancel()
|
|
438 |
// post increment makes sure OnComplete decorators are rendered
|
|
439 |
s.shutdown++
|
| 434 | 440 |
}
|
| 435 | 441 |
b.frameCh <- frame
|
| 436 | 442 |
}
|
| 437 | 443 |
select {
|
| 438 | 444 |
case b.operateState <- fn:
|
| 439 | 445 |
case <-b.done:
|
| 440 | |
done = true
|
| 441 | 446 |
fn(b.bs)
|
| 442 | 447 |
}
|
| 443 | 448 |
}
|
| 333 | 333 |
_, _ = io.Copy(io.Discard, row)
|
| 334 | 334 |
}
|
| 335 | 335 |
}
|
| 336 | |
if frame.shutdown {
|
| 337 | |
b.Wait() // waiting for b.done, so it's safe to read b.bs
|
|
336 |
if frame.shutdown != 0 {
|
| 338 | 337 |
if qb, ok := s.queueBars[b]; ok {
|
|
338 |
b.cancel()
|
| 339 | 339 |
delete(s.queueBars, b)
|
| 340 | 340 |
qb.priority = b.priority
|
| 341 | 341 |
wg.Add(1)
|
|
| 345 | 345 |
}(qb)
|
| 346 | 346 |
continue
|
| 347 | 347 |
}
|
| 348 | |
if s.popCompleted && !b.bs.noPop {
|
| 349 | |
switch b.bs.shutdown++; b.bs.shutdown {
|
|
348 |
if s.popCompleted && !frame.noPop {
|
|
349 |
switch frame.shutdown {
|
| 350 | 350 |
case 1:
|
| 351 | 351 |
b.priority = s.popPriority
|
| 352 | 352 |
s.popPriority++
|
| 353 | 353 |
default:
|
| 354 | |
if b.bs.dropOnComplete {
|
| 355 | |
popCount += usedRows
|
| 356 | |
continue
|
| 357 | |
}
|
|
354 |
b.cancel()
|
|
355 |
popCount += usedRows
|
|
356 |
continue
|
| 358 | 357 |
}
|
| 359 | |
} else if b.bs.dropOnComplete {
|
|
358 |
} else if frame.rmOnComplete {
|
|
359 |
b.cancel()
|
| 360 | 360 |
continue
|
|
361 |
} else {
|
|
362 |
b.cancel()
|
| 361 | 363 |
}
|
| 362 | 364 |
}
|
| 363 | 365 |
wg.Add(1)
|