forked from TrueCloudLab/restic
Merge pull request #266 from bchapuis/fix-263
Update the progress status with the ticker
This commit is contained in:
commit
a4cb8995a8
1 changed files with 19 additions and 8 deletions
27
progress.go
27
progress.go
|
@ -6,19 +6,22 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
const minTickerTime = time.Second / 60
|
||||
|
||||
type Progress struct {
|
||||
OnStart func()
|
||||
OnUpdate ProgressFunc
|
||||
OnDone ProgressFunc
|
||||
fnM sync.Mutex
|
||||
|
||||
cur Stat
|
||||
curM sync.Mutex
|
||||
start time.Time
|
||||
c *time.Ticker
|
||||
cancel chan struct{}
|
||||
o sync.Once
|
||||
d time.Duration
|
||||
cur Stat
|
||||
curM sync.Mutex
|
||||
start time.Time
|
||||
c *time.Ticker
|
||||
cancel chan struct{}
|
||||
o sync.Once
|
||||
d time.Duration
|
||||
lastUpdate time.Time
|
||||
|
||||
running bool
|
||||
}
|
||||
|
@ -92,9 +95,17 @@ 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()
|
||||
|
||||
p.updateProgress(cur, false)
|
||||
if needUpdate {
|
||||
p.updateProgress(cur, false)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (p *Progress) updateProgress(cur Stat, ticker bool) {
|
||||
|
|
Loading…
Reference in a new issue