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