added comments for worker pool

This commit is contained in:
Jian Han 2017-11-07 14:48:16 +10:00
parent eaf058c860
commit c97546965b

View File

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