From 3b6279ddf21ca58b8cf9469c04a249d69ea449cb Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 18 Apr 2018 16:28:37 -0400 Subject: add comments, fiddle with function publicity --- jwg.go | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'jwg.go') diff --git a/jwg.go b/jwg.go index a7fd343..5b4f8a8 100644 --- a/jwg.go +++ b/jwg.go @@ -7,12 +7,15 @@ import ( "time" ) +// JobWaitGroup is like sync.WaitGroup, but keeps track of job status, +// and tracks how long each job took. type JobWaitGroup struct { lock sync.RWMutex jobs map[string]time.Duration wg sync.WaitGroup } +// Do a job. func (jwg *JobWaitGroup) Do(name string, fn func()) { jwg.lock.Lock() defer jwg.lock.Unlock() @@ -37,11 +40,14 @@ func (jwg *JobWaitGroup) Do(name string, fn func()) { }() } +// Wait for all jobs to finish, and return how long each job took. func (jwg *JobWaitGroup) Wait() map[string]time.Duration { jwg.wg.Wait() return jwg.jobs } +// Status returns the total number of jobs that have been started, and +// a list of still-running jobs. func (jwg *JobWaitGroup) Status() (int, []string) { jwg.lock.RLock() -- cgit v1.2.3