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 (
|
import (
|
||||||
"io"
|
"io"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/time/rate"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Reader is a Reader with progress bar.
|
// Reader is a Reader with progress bar.
|
||||||
|
@ -13,6 +16,7 @@ type Reader struct {
|
||||||
lastUpdate int64
|
lastUpdate int64
|
||||||
id string
|
id string
|
||||||
action string
|
action string
|
||||||
|
rateLimiter *rate.Limiter
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewProgressReader creates a new ProgressReader.
|
// NewProgressReader creates a new ProgressReader.
|
||||||
|
@ -23,6 +27,7 @@ func NewProgressReader(in io.ReadCloser, out Output, size int64, id, action stri
|
||||||
size: size,
|
size: size,
|
||||||
id: id,
|
id: id,
|
||||||
action: action,
|
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) {
|
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})
|
p.out.WriteProgress(Progress{ID: p.id, Action: p.action, Current: p.current, Total: p.size, LastUpdate: last})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue