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.
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]) 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