From c97546965b67b419c7cc2fd5c69b306b7e2525ff Mon Sep 17 00:00:00 2001 From: Jian Han Date: Tue, 7 Nov 2017 14:48:16 +1000 Subject: [PATCH] added comments for worker pool --- workerpool/main.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/workerpool/main.go b/workerpool/main.go index 26dfc75..5418b43 100644 --- a/workerpool/main.go +++ b/workerpool/main.go @@ -8,15 +8,25 @@ import ( "github.com/labstack/gommon/log" ) +// Task encapsulates a work item that should go in a work +// pool. type Task struct { + // Err holds an error that occurred during a task. Its + // result is only meaningful after Run has been called + // for the pool that holds it. Err error - f func() error + + f func() error } +// NewTask initializes a new task based on a given work +// function. func NewTask(f func() error) *Task { return &Task{f: f} } +// Run runs a Task and does appropriate accounting via a +// given sync.WorkGroup. func (t *Task) Run(wg *sync.WaitGroup) { t.Err = t.f() wg.Done()