diff options
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() |