From 702cf3c2ffe965c2d9dd60dbac0f69ade809cc9b Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sun, 22 Mar 2015 14:19:16 +0100 Subject: [PATCH] Progress: Add function that is called on Start() --- progress.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/progress.go b/progress.go index c84b91640..f8725a48d 100644 --- a/progress.go +++ b/progress.go @@ -7,6 +7,7 @@ import ( ) type Progress struct { + OnStart func() OnUpdate ProgressFunc OnDone ProgressFunc fnM sync.Mutex @@ -32,10 +33,11 @@ type Stat struct { type ProgressFunc func(s Stat, runtime time.Duration, ticker bool) -// NewProgress returns a new progress reporter. After Start() has been called, -// the function OnUpdate is called when new data arrives or at least every d -// interval. The function OnDone is called when Done() is called. Both -// functions are called synchronously and can use shared state. +// NewProgress returns a new progress reporter. When Start() called, the +// function OnStart is executed once. Afterwards the function OnUpdate is +// called when new data arrives or at least every d interval. The function +// OnDone is called when Done() is called. Both functions are called +// synchronously and can use shared state. func NewProgress(d time.Duration) *Progress { return &Progress{d: d} } @@ -53,6 +55,10 @@ func (p *Progress) Start() { p.start = time.Now() p.c = time.NewTicker(p.d) + if p.OnStart != nil { + p.OnStart() + } + go p.reporter() }