Documentation ¶
Index ¶
- type Option
- type Pool
- func (p *Pool) Do(t *Task)
- func (p *Pool) Execute(exec func(context.Context) (interface{}, error)) (t *Task)
- func (p *Pool) ExecuteWithCtx(ctx context.Context, exec func(context.Context) (interface{}, error)) (t *Task)
- func (p *Pool) Start()
- func (p *Pool) Stop()
- func (p *Pool) TryDo(t *Task) (addedToQueue bool)
- func (p *Pool) TryExecute(exec func(context.Context) (interface{}, error)) (t *Task, addedToQueue bool)
- func (p *Pool) TryExecuteWithCtx(ctx context.Context, exec func(context.Context) (interface{}, error)) (t *Task, addedToQueue bool)
- type Task
- type TaskResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option struct { // NumberWorker number of workers. // Default: runtime.NumCPU() NumberWorker int `yaml:"number_worker" json:"number_worker"` // ExpandableLimit limits number of workers to be expanded on demand. // Default: 0 (no expandable) ExpandableLimit int32 `yaml:"expandable_limit" json:"expandable_limit"` // ExpandedLifetime represents lifetime of expanded worker (in nanoseconds)/ // Default: 1 minute. ExpandedLifetime time.Duration `yaml:"expanded_lifetime" json:"expanded_lifetime"` }
Option represents pool option.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool is a lightweight worker pool with capable of auto-expand on demand.
func (*Pool) ExecuteWithCtx ¶
func (p *Pool) ExecuteWithCtx(ctx context.Context, exec func(context.Context) (interface{}, error)) (t *Task)
ExecuteWithCtx a task with custom context.
func (*Pool) TryDo ¶
TryDo try to execute a task. If task queue is full, returns immediately and addedToQueue is false.
type Task ¶
type Task struct {
// contains filtered or unexported fields
}
Task represent a task.
type TaskResult ¶
type TaskResult struct { Result interface{} Err error }
TaskResult represent result of task.
Click to show internal directories.
Click to hide internal directories.