Documentation ¶
Overview ¶
Package result provides concurrency utilities for accumulating results and managing errors.
Example
import ( result "github.com/neurocode-io/go-pkgs/result" "context" ) func worker() ([]int, error) { // worker logic here return []int{1, 2, 3}, nil } ctx := context.Background() group, ctx := result.WithErrorsThreshold[int](ctx, 2) group.Go(worker) results, err := group.Wait() if err != nil { handle error } results == []int{1, 2, 3}
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Group ¶
type Group[T any] struct { // contains filtered or unexported fields }
func WithErrorsThreshold ¶
WithErrorsThreshold initializes a new Group[T] with a threshold for error tolerance.
Example
ctx := context.Background() group, ctx := result.WithErrorsThreshold[int](ctx, 2) // group is now ready to execute with a threshold of 2 errors
func (*Group[T]) Go ¶
Go starts a goroutine that performs a given function and handles its results and errors.
Example
group.Go(func() ([]int, error) { return []int{1, 2, 3}, nil }) // The results will be accumulated and errors managed based on the Group's settings.
func (*Group[T]) Wait ¶
func (g *Group[T]) Wait() ([]T, errorWithUnwrap)
Wait blocks until all tasks have completed and returns the accumulated results and any errors.
Example
results, err := group.Wait() if err != nil { // handle error } // results contains all accumulated results from the group operations
Click to show internal directories.
Click to hide internal directories.