mirror of
https://github.com/octoleo/restic.git
synced 2024-11-25 14:17:42 +00:00
Progress: Add function that is called on Start()
This commit is contained in:
parent
f2df072f48
commit
702cf3c2ff
14
progress.go
14
progress.go
@ -7,6 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Progress struct {
|
type Progress struct {
|
||||||
|
OnStart func()
|
||||||
OnUpdate ProgressFunc
|
OnUpdate ProgressFunc
|
||||||
OnDone ProgressFunc
|
OnDone ProgressFunc
|
||||||
fnM sync.Mutex
|
fnM sync.Mutex
|
||||||
@ -32,10 +33,11 @@ type Stat struct {
|
|||||||
|
|
||||||
type ProgressFunc func(s Stat, runtime time.Duration, ticker bool)
|
type ProgressFunc func(s Stat, runtime time.Duration, ticker bool)
|
||||||
|
|
||||||
// NewProgress returns a new progress reporter. After Start() has been called,
|
// NewProgress returns a new progress reporter. When Start() called, the
|
||||||
// the function OnUpdate is called when new data arrives or at least every d
|
// function OnStart is executed once. Afterwards the function OnUpdate is
|
||||||
// interval. The function OnDone is called when Done() is called. Both
|
// called when new data arrives or at least every d interval. The function
|
||||||
// functions are called synchronously and can use shared state.
|
// OnDone is called when Done() is called. Both functions are called
|
||||||
|
// synchronously and can use shared state.
|
||||||
func NewProgress(d time.Duration) *Progress {
|
func NewProgress(d time.Duration) *Progress {
|
||||||
return &Progress{d: d}
|
return &Progress{d: d}
|
||||||
}
|
}
|
||||||
@ -53,6 +55,10 @@ func (p *Progress) Start() {
|
|||||||
p.start = time.Now()
|
p.start = time.Now()
|
||||||
p.c = time.NewTicker(p.d)
|
p.c = time.NewTicker(p.d)
|
||||||
|
|
||||||
|
if p.OnStart != nil {
|
||||||
|
p.OnStart()
|
||||||
|
}
|
||||||
|
|
||||||
go p.reporter()
|
go p.reporter()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user