group

package
v0.0.0-...-084e4ab Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Execute

func Execute(ctx context.Context, strategy ExecutionStrategy, members []Member) ([]proto.Message, error)

Execute runs all members according to the provided strategy.

func ExecuteAll

func ExecuteAll(ctx context.Context, members []Member) ([]proto.Message, error)

ExecuteAll executes all the member functions in parallel, if any return errors then this will return the first reported error. Incomplete executions will have their context cancelled on error, but this function will not return until all execution have completed.

func ExecuteAny

func ExecuteAny(ctx context.Context, members []Member) ([]proto.Message, error)

ExecuteAny executes all the member functions in parallel, if all the members error then this will return the first reported error. Incomplete executions will have their context cancelled on error, but this function will not return until all execution have completed.

func ExecuteFast

func ExecuteFast(ctx context.Context, members []Member) (proto.Message, int, error)

ExecuteFast executes all the member functions in parallel, the first non-err response from a member is returned. If all members error then the first error response is returned.

func ExecuteMost

func ExecuteMost(ctx context.Context, members []Member) ([]proto.Message, error)

ExecuteMost executes all the member functions in parallel, if more than half of the members error then this will return the first reported error. Incomplete executions will have their context cancelled on error, but this function will not return until all execution have completed.

func ExecuteOne

func ExecuteOne(ctx context.Context, members []Member) (proto.Message, int, error)

ExecuteOne executes the first member, if it fails, executes the next, etc. Returns the first successful response and the member index that succeeded. If all fail, the first error recorded will be returned.

func ExecuteRace

func ExecuteRace(ctx context.Context, members []Member) (proto.Message, int, error)

ExecuteRace executes all the member functions in parallel, the first response from a member is returned.

func ExecuteUpTo

func ExecuteUpTo(ctx context.Context, allowedErrors int, members []Member) ([]proto.Message, error)

ExecuteUpTo executes all the member functions in parallel, if more than allowedErrors members return errors then this will return the first reported error. Incomplete executions will have their context cancelled on error, but this function will not return until all execution have completed.

Types

type ExecutionStrategy

type ExecutionStrategy int

ExecutionStrategy defines the possible methods for combining a collection of operations into one result.

const (
	ExecutionStrategyUnspecified ExecutionStrategy = iota // Implementation will chose a strategy

	ExecutionStrategyAll  // Execute all, return first error if any fail
	ExecutionStrategyMost // Execute all, return first error if most fail
	ExecutionStrategyAny  // Execute all, return first error if all fail
	ExecutionStrategyOne  // Execute one, if fail, try the next, return first error if all fail
	ExecutionStrategyFast // Execute all, return first to successfully respond or first error if all fail
	ExecutionStrategyRace // Execute all, return first to respond even if it errors
)

type Member

type Member func(context.Context) (proto.Message, error)

Member defines some action to be taken as part of a group.

Jump to

Keyboard shortcuts

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