sync

package
v2.0.0-...-fe6a7a6 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package sync provides ways to execute multiple tasks concurrently while synchronously managing them at the same time.

Package sync provides ways to execute multiple tasks concurrently while synchronously managing them at the same time.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

Pool provides a way to execute multiple tasks concurrently and synchronously wait for all of them to finish. It also recovers from panics within the tasks and support sentry tracing.

func NewPool

func NewPool(ctx context.Context, opts ...PoolOption) *Pool

NewPool creates a new pool with the given context and options.

func (*Pool) Go

func (p *Pool) Go(f func(ctx context.Context) error)

Go executes a task concurrently. It return a panic event as an error, not a panic if any.

func (*Pool) Wait

func (p *Pool) Wait() error

Wait waits for all tasks to finish and get an error (or multi joined errors) if any.

type PoolOption

type PoolOption func(*poolOptions)

PoolOption provides options to configure the pool.

func WithCancelOnFirstErr

func WithCancelOnFirstErr() PoolOption

WithCancelOnFirstErr cancels all tasks when the first error occurs.

func WithMaxGoroutines

func WithMaxGoroutines(max int) PoolOption

WithMaxGoroutines sets the maximum number of goroutines that can be executed concurrently.

func WithRequest

func WithRequest(req *http.Request) PoolOption

WithRequest sets a http request for sentry tracing.

type ResultPool

type ResultPool[T any] struct {
	// contains filtered or unexported fields
}

func NewResultPool

func NewResultPool[T any](ctx context.Context, opts ...ResultPoolOption) ResultPool[T]

func (*ResultPool[T]) Go

func (p *ResultPool[T]) Go(f func(ctx context.Context) (T, error))

func (*ResultPool[T]) Wait

func (p *ResultPool[T]) Wait() ([]T, error)

type ResultPoolOption

type ResultPoolOption func(*resultPoolOptions)

func WithCollectErroredRlts

func WithCollectErroredRlts() ResultPoolOption

func WithRltCancelOnFirstErr

func WithRltCancelOnFirstErr() ResultPoolOption

func WithRltMaxGoroutines

func WithRltMaxGoroutines(max int) ResultPoolOption

func WithRltRequest

func WithRltRequest(req *http.Request) ResultPoolOption

Jump to

Keyboard shortcuts

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