diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2018-04-18 16:28:37 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2018-04-18 16:28:37 -0400 |
commit | 3b6279ddf21ca58b8cf9469c04a249d69ea449cb (patch) | |
tree | dbbe3febfc4d4aa889fee787d4d934b9f4720d07 /jwg.go | |
parent | 45717808e4c8861e022e838aacb8215c81dcd327 (diff) |
add comments, fiddle with function publicity
Diffstat (limited to 'jwg.go')
-rw-r--r-- | jwg.go | 6 |
1 files changed, 6 insertions, 0 deletions
@@ -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() |