Skip to content

Commit

Permalink
Remove each progress bar immediately upon completion
Browse files Browse the repository at this point in the history
  • Loading branch information
brianaydemir committed Dec 7, 2024
1 parent c345e67 commit 5db33a0
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions cmd/progress_bars.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (pb *progressBars) launchDisplay(ctx context.Context) {
progressCtr.Wait()
}()

tickDuration := 200 * time.Millisecond
tickDuration := 500 * time.Millisecond
ticker := time.NewTicker(tickDuration)
defer ticker.Stop()
pbMap := make(map[string]*progressBar)
Expand All @@ -98,8 +98,8 @@ func (pb *progressBars) launchDisplay(ctx context.Context) {
return ctx.Err()
case <-pb.done:
for path := range pbMap {
// The deferred `progressCtr.Wait()` above will handle final cleanup.
pbMap[path].bar.Abort(true)
pbMap[path].bar.Wait()
}
return nil
case <-ticker.C:
Expand All @@ -122,13 +122,15 @@ func (pb *progressBars) launchDisplay(ctx context.Context) {
decor.OnComplete(decor.Name(" ] "), ""),
decor.OnComplete(decor.EwmaSpeed(decor.SizeB1024(0), "% .2f", 15), "Done!"),
),
mpb.BarRemoveOnComplete(),
),
}
}
oldStatus := pbMap[path].progressStatus
newStatus := pb.status[path]
if oldStatus.size == 0 && newStatus.size > 0 {
pbMap[path].bar.SetTotal(newStatus.size, false)
pbMap[path].bar.EnableTriggerComplete()
}
pbMap[path].bar.EwmaSetCurrent(newStatus.xfer, tickDuration)
pbMap[path].progressStatus = newStatus
Expand All @@ -142,7 +144,6 @@ func (pb *progressBars) launchDisplay(ctx context.Context) {
for _, path := range toDelete {
bar := pbMap[path].bar
bar.Abort(true)
bar.Wait()
delete(pbMap, path)
}
}()
Expand Down

0 comments on commit 5db33a0

Please sign in to comment.