mirror of
https://github.com/crazybber/awesome-patterns.git
synced 2024-11-21 20:36:01 +03:00
added comments for worker pool
This commit is contained in:
parent
eaf058c860
commit
c97546965b
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user