worker

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Future

type Future struct {
	// contains filtered or unexported fields
}

Future holds the result of an asynchronous task.

func (*Future) Wait

func (f *Future) Wait() error

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

Pool is a fixed-size worker pool for concurrent task execution.

func NewPool

func NewPool(n int) *Pool

NewPool creates a fixed-size worker pool of n goroutines.

Example:

pool := worker.NewPool(4)
defer pool.Shutdown()
pool.Submit(func(ctx context.Context) error {
	return doWork(ctx)
})

func (*Pool) Shutdown

func (p *Pool) Shutdown()

Shutdown stops accepting new tasks and waits for in-progress work to finish. The task channel is unbuffered, so no tasks can be pending pickup when done is closed; any Submit in progress will observe done and return false.

func (*Pool) Submit

func (p *Pool) Submit(task Task) bool

Submit enqueues a task for execution. Returns false if the pool is shut down or shutting down; the task is not executed in that case.

type Result

type Result struct {
	Err error
}

Result holds the outcome of a completed Task.

type Task

type Task func(context.Context) error

Task is a work function executed by the pool.

Jump to

Keyboard shortcuts

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