Documentation
¶
Index ¶
- Constants
- Variables
- type Exec
- func (e *Exec) Close(ctx context.Context) error
- func (e *Exec) Do(task func()) error
- func (e *Exec) DoCtx(ctx context.Context, task func()) error
- func (e *Exec) Name() string
- func (e *Exec) Resize(n int) error
- func (e *Exec) Start(ctx context.Context) error
- func (e *Exec) Stats() Stats
- func (e *Exec) Stop(timeout time.Duration) error
- func (e *Exec) Wait() error
- type Executor
- type Opts
- type QueuedExec
- func (e *QueuedExec) Do(task func()) error
- func (e *QueuedExec) DoCtx(ctx context.Context, task func()) error
- func (e *QueuedExec) DoCtxPriority(ctx context.Context, task func(), priority int) error
- func (e *QueuedExec) DoPriority(task func(), priority int) error
- func (e *QueuedExec) Resize(n int) error
- func (e *QueuedExec) Stats() Stats
- func (e *QueuedExec) Stop(timeout time.Duration) error
- func (e *QueuedExec) Wait() error
- type QueuedOpts
- type QueuedTask
- type ScheduledTask
- type Scheduler
- type Stats
Constants ¶
const ( PriorityLow = iota PriorityNormal PriorityHigh )
Priority levels
Variables ¶
var ( ErrClosed = errors.New("executor closed") ErrFull = errors.New("queue full") )
Functions ¶
This section is empty.
Types ¶
type Exec ¶
type Exec struct {
// contains filtered or unexported fields
}
Exec is an executor
type Executor ¶
type Executor interface {
Do(task func()) error
DoCtx(ctx context.Context, task func()) error
Wait() error
Stop(timeout time.Duration) error
Stats() Stats
}
Executor executes tasks
type Opts ¶
type Opts struct {
Name string
Workers int
QueueSize int
NonBlocking bool
OnPanic func(interface{})
NoStats bool
}
Opts configures executor
type QueuedExec ¶
type QueuedExec struct {
// contains filtered or unexported fields
}
QueuedExec is an executor with multiple queues and work stealing
func NewQueued ¶
func NewQueued(opts QueuedOpts) (*QueuedExec, error)
NewQueued creates a queued executor with work stealing
func (*QueuedExec) Do ¶
func (e *QueuedExec) Do(task func()) error
Do schedules task with normal priority
func (*QueuedExec) DoCtx ¶
func (e *QueuedExec) DoCtx(ctx context.Context, task func()) error
DoCtx schedules task with context
func (*QueuedExec) DoCtxPriority ¶
func (e *QueuedExec) DoCtxPriority(ctx context.Context, task func(), priority int) error
DoCtxPriority schedules task with context and priority
func (*QueuedExec) DoPriority ¶
func (e *QueuedExec) DoPriority(task func(), priority int) error
DoPriority schedules task with specified priority
type QueuedOpts ¶
type QueuedOpts struct {
Name string
Workers int
QueueSize int
NonBlocking bool
OnPanic func(interface{})
NoStats bool
}
QueuedOpts configures queued executor
type QueuedTask ¶
type QueuedTask struct {
Task func()
Priority int
}
QueuedTask represents a task with priority
type ScheduledTask ¶ added in v0.4.0
type ScheduledTask struct {
// contains filtered or unexported fields
}
ScheduledTask represents a single scheduled function.
type Scheduler ¶ added in v0.4.0
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler executes scheduled tasks at or after a specific time.
func NewScheduler ¶ added in v0.4.0
func NewScheduler() *Scheduler
NewScheduler creates a new Scheduler and starts its dispatcher goroutine.
func (*Scheduler) Cancel ¶ added in v0.4.0
func (s *Scheduler) Cancel(t *ScheduledTask)
Cancel marks a scheduled task as cancelled. It will be skipped when its turn comes; we don't remove it eagerly from the heap to keep locking simple.