executor

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 7, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PriorityLow = iota
	PriorityNormal
	PriorityHigh
)

Priority levels

Variables

View Source
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

func New

func New(opts Opts) (*Exec, error)

New creates an executor

func (*Exec) Close added in v0.3.4

func (e *Exec) Close(ctx context.Context) error

func (*Exec) Do

func (e *Exec) Do(task func()) error

Do schedules task

func (*Exec) DoCtx

func (e *Exec) DoCtx(ctx context.Context, task func()) error

DoCtx schedules task with context

func (*Exec) Name added in v0.3.4

func (e *Exec) Name() string

lifecycle.Component implementation

func (*Exec) Resize

func (e *Exec) Resize(n int) error

Resize changes worker count

func (*Exec) Start added in v0.3.4

func (e *Exec) Start(ctx context.Context) error

func (*Exec) Stats

func (e *Exec) Stats() Stats

Stats returns current statistics

func (*Exec) Stop

func (e *Exec) Stop(timeout time.Duration) error

Stop gracefully stops executor

func (*Exec) Wait

func (e *Exec) Wait() error

Wait blocks until queue drains

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

func (*QueuedExec) Resize

func (e *QueuedExec) Resize(n int) error

Resize changes worker count

func (*QueuedExec) Stats

func (e *QueuedExec) Stats() Stats

Stats returns current statistics

func (*QueuedExec) Stop

func (e *QueuedExec) Stop(timeout time.Duration) error

Stop gracefully stops executor

func (*QueuedExec) Wait

func (e *QueuedExec) Wait() error

Wait blocks until queues drain

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.

func (*Scheduler) Close added in v0.4.0

func (s *Scheduler) Close()

Close stops the scheduler and drops all pending tasks.

func (*Scheduler) Schedule added in v0.4.0

func (s *Scheduler) Schedule(d time.Duration, fn func()) *ScheduledTask

Schedule schedules fn to run once after delay d and returns a handle that can be used to cancel the task before it fires.

type Stats

type Stats struct {
	Cap     int
	Running int
	Queued  int
	Done    uint64
	Dropped uint64
}

Stats exposes runtime metrics

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL