parent
f0acc77a4b
commit
fcc0b0d089
13 changed files with 81 additions and 33 deletions
@ -1,4 +1,4 @@ |
||||
package Utils |
||||
package utils |
||||
|
||||
import ( |
||||
"encoding/json" |
@ -1,4 +1,4 @@ |
||||
package Utils |
||||
package utils |
||||
|
||||
import ( |
||||
"encoding/json" |
@ -0,0 +1,18 @@ |
||||
package workerpool |
||||
|
||||
import "fmt" |
||||
|
||||
type Task struct { |
||||
Err error |
||||
Data interface{} |
||||
f func(interface{}) error |
||||
} |
||||
|
||||
func NewTask(f func(interface{}) error, data interface{}) *Task { |
||||
return &Task{f: f, Data: data} |
||||
} |
||||
|
||||
func process(workerID int, task *Task) { |
||||
fmt.Println("Worker %d processes task %v\n", workerID, task.Data) |
||||
task.Err = task.f(task.Data) |
||||
} |
@ -0,0 +1,6 @@ |
||||
package workerpool |
||||
|
||||
type Worker struct { |
||||
ID int |
||||
taskChan chan *Task |
||||
} |
Loading…
Reference in new issue