Commit e7888cff authored by watermelon's avatar watermelon

opt: impl simple task poll

parent 2a672f6b
......@@ -13,6 +13,7 @@ const (
// Task Pool Options
/////////////////////////////////////////
// TaskPoolOption is optional settings for task pool
type TaskPoolOptions struct {
tQLen int // task queue length. buffer size per queue
tQNumber int // task queue number. number of queue
......@@ -39,21 +40,21 @@ func (o *TaskPoolOptions) validate() {
type TaskPoolOption func(*TaskPoolOptions)
// @size is the task queue pool size
// WithTaskPoolTaskQueueLength set @size of the task queue pool size
func WithTaskPoolTaskPoolSize(size int) TaskPoolOption {
return func(o *TaskPoolOptions) {
o.tQPoolSize = size
}
}
// @length is the task queue length
// WithTaskPoolTaskQueueLength set @length of the task queue length
func WithTaskPoolTaskQueueLength(length int) TaskPoolOption {
return func(o *TaskPoolOptions) {
o.tQLen = length
}
}
// @number is the task queue number
// WithTaskPoolTaskQueueNumber set @number of the task queue number
func WithTaskPoolTaskQueueNumber(number int) TaskPoolOption {
return func(o *TaskPoolOptions) {
o.tQNumber = number
......
......@@ -35,6 +35,7 @@ import (
type task func()
// GenericTaskPool represents an generic task pool.
type GenericTaskPool interface {
// AddTask wait idle worker add task
AddTask(t task) bool
......@@ -64,7 +65,7 @@ type TaskPool struct {
done chan struct{}
}
// build a task pool
// NewTaskPool build a task pool
func NewTaskPool(opts ...TaskPoolOption) GenericTaskPool {
var tOpts TaskPoolOptions
for _, opt := range opts {
......@@ -226,6 +227,7 @@ type taskPoolSimple struct {
sem chan struct{}
}
// NewTaskPoolSimple build a simple task pool
func NewTaskPoolSimple(size int) GenericTaskPool {
if size < 1 {
size = runtime.NumCPU() * 100
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment