executor

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSkip       = errors.New("skip")
	ErrAllSkipped = errors.New("all skipped")
)

Functions

This section is empty.

Types

type Context

type Context[Arg, Res any] struct {
	context.Context
	// contains filtered or unexported fields
}

type Executor

type Executor[Arg, Res any] struct {
	// contains filtered or unexported fields
}

Executor is a generic struct for managing job execution.

func New

func New[Arg, Res any](n int64) *Executor[Arg, Res]

New creates a new Executor with a specified number of workers. If n <= 0, it uses the default workers.

func (*Executor[Arg, Res]) Execute

func (e *Executor[Arg, Res]) Execute(argMethod, fnMethod Method, args []Arg, fn ...func(Arg) (Res, error)) (res Res, err error)

Execute gets the result from the functions with several args by specified method. If both argMethod and fnMethod is Concurrent, fnMethod will be first.

func (*Executor[Arg, Res]) ExecuteConcurrentArg

func (e *Executor[Arg, Res]) ExecuteConcurrentArg(arg []Arg, fn ...func(Arg) (Res, error)) (Res, error)

ExecuteConcurrentArg gets the fastest result from the functions with args, args will be run concurrently.

func (*Executor[Arg, Res]) ExecuteConcurrentFunc

func (e *Executor[Arg, Res]) ExecuteConcurrentFunc(arg []Arg, fn ...func(Arg) (Res, error)) (Res, error)

ExecuteConcurrentFunc gets the fastest result from the functions with args, functions will be run concurrently.

func (*Executor[Arg, Res]) ExecuteRandom

func (e *Executor[Arg, Res]) ExecuteRandom(arg []Arg, fn ...func(Arg) (Res, error)) (Res, error)

ExecuteRandom gets the result until success from the functions with args randomly.

func (*Executor[Arg, Res]) ExecuteSerial

func (e *Executor[Arg, Res]) ExecuteSerial(arg []Arg, fn ...func(Arg) (Res, error)) (Res, error)

ExecuteSerial gets the result until success from the functions with args in order.

type Method

type Method int

Method represents the execute method.

const (
	// Concurrent method. Executing at the same time.
	Concurrent Method = iota
	// Serial method. Executing in order.
	Serial
	// Random method. Executing randomly.
	Random
)

Jump to

Keyboard shortcuts

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