executor

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 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 Executor

type Executor[Arg, Res any] int

Executor is a generic type for managing job execution.

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