mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #26584 from aaronlehmann/rate-limit-progress-bar
progress: Rate limit progress bar output
This commit is contained in:
commit
b248de7e33
1 changed files with 20 additions and 13 deletions
|
@ -2,6 +2,9 @@ package progress
|
|||
|
||||
import (
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"golang.org/x/time/rate"
|
||||
)
|
||||
|
||||
// Reader is a Reader with progress bar.
|
||||
|
@ -13,6 +16,7 @@ type Reader struct {
|
|||
lastUpdate int64
|
||||
id string
|
||||
action string
|
||||
rateLimiter *rate.Limiter
|
||||
}
|
||||
|
||||
// NewProgressReader creates a new ProgressReader.
|
||||
|
@ -23,6 +27,7 @@ func NewProgressReader(in io.ReadCloser, out Output, size int64, id, action stri
|
|||
size: size,
|
||||
id: id,
|
||||
action: action,
|
||||
rateLimiter: rate.NewLimiter(rate.Every(100*time.Millisecond), 1),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -55,5 +60,7 @@ func (p *Reader) Close() error {
|
|||
}
|
||||
|
||||
func (p *Reader) updateProgress(last bool) {
|
||||
if last || p.current == p.size || p.rateLimiter.Allow() {
|
||||
p.out.WriteProgress(Progress{ID: p.id, Action: p.action, Current: p.current, Total: p.size, LastUpdate: last})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue