Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Result ¶
type Result struct { Value interface{} Error error }
Result is struct to represent result of Task, which is either some kind of value or error if any occured.
type Task ¶
type Task interface{}
Task represents abstract type to hold any value which will be delieverd to workers as a value to process.
type WorkerPool ¶
type WorkerPool struct {
// contains filtered or unexported fields
}
WorkerPool is struct to represent pool of workers to which one can send task and receive results.
func NewWorkerPool ¶
func NewWorkerPool(handler func(value Task) *Result) *WorkerPool
NewWorkerPool creates new instance of `WorkerPool`. As parameter it receives `handler` which is function that is responsible for processing task and returning the result.
func (*WorkerPool) Close ¶
func (wp *WorkerPool) Close()
Close finishes all workers and closes all channels.
func (*WorkerPool) GetResult ¶
func (wp *WorkerPool) GetResult() *Result
GetResult returns first result from result queue or blocks until new one appears.
func (*WorkerPool) PostTask ¶
func (wp *WorkerPool) PostTask(task Task)
PostTask adds new task to task queue. Adding tasks after `Close` results in panic.