executor

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrFullExecutor = errors.New("pool has no idle goroutine")

ErrFullExecutor is returned by the executor created by NewAbortOnFullExecutor if there are no goroutines available to run a task.

Functions

This section is empty.

Types

type ExecuteCloser

type ExecuteCloser interface {
	Executor

	// Close signals the goroutines in this executor to stop.
	Close() error
}

ExecuteCloser adds io.Closer to Executor.

func NewAbortOnFullExecutor

func NewAbortOnFullExecutor(n int) ExecuteCloser

NewAbortOnFullExecutor returns a new Executor that will return NewAbortOnFullExecutor if a new pool of n goroutines has no idle worker to pick up a task.

Passing n == 0 effectively an executor that always returns NewAbortOnFullExecutor. Panics if n < 0.

func NewCallerRunsOnFullExecutor

func NewCallerRunsOnFullExecutor(n int) ExecuteCloser

NewCallerRunsOnFullExecutor returns a new Executor that will execute the command on same goroutine as caller if a new pool of n goroutines is full.

Passing n == 0 effectively returns an always-caller-run executor. Panics if n < 0.

type Executor

type Executor interface {
	// Execute executes the given command.
	//
	// The return error comes from the executor's attempt to run the function, not from the function itself.
	Execute(func()) error
}

Executor is inspired by Java Executor that abstracts submitting a task and executing it.

Jump to

Keyboard shortcuts

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