mirror of
https://github.com/restic/restic.git
synced 2025-08-22 13:27:45 +00:00
Update progress status when necessary
This commit is contained in:
11
progress.go
11
progress.go
@@ -6,6 +6,8 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const minTickerTime = time.Second / 60
|
||||
|
||||
type Progress struct {
|
||||
OnStart func()
|
||||
OnUpdate ProgressFunc
|
||||
@@ -19,6 +21,7 @@ type Progress struct {
|
||||
cancel chan struct{}
|
||||
o sync.Once
|
||||
d time.Duration
|
||||
lastUpdate time.Time
|
||||
|
||||
running bool
|
||||
}
|
||||
@@ -92,11 +95,19 @@ func (p *Progress) Report(s Stat) {
|
||||
p.curM.Lock()
|
||||
p.cur.Add(s)
|
||||
cur := p.cur
|
||||
needUpdate := false
|
||||
if time.Since(p.lastUpdate) > minTickerTime {
|
||||
p.lastUpdate = time.Now()
|
||||
needUpdate = true
|
||||
}
|
||||
p.curM.Unlock()
|
||||
|
||||
if needUpdate {
|
||||
p.updateProgress(cur, false)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (p *Progress) updateProgress(cur Stat, ticker bool) {
|
||||
if p.OnUpdate == nil {
|
||||
return
|
||||
|
Reference in New Issue
Block a user