pool

package
v1.0.207 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2026 License: MIT Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAllTasksDone = errors.New("all tasks completed")

Functions

This section is empty.

Types

type Pool

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

Pool[T any] is a goroutine pool that allows parallel task execution.

func New

func New[T any]() *Pool[T]

New[T any] creates a new goroutine pool.

func (*Pool[T]) ActiveTasks

func (p *Pool[T]) ActiveTasks() int

ActiveTasks returns the current number of tasks that are still running.

func (*Pool[T]) Cancel

func (p *Pool[T]) Cancel(err ...error)

Cancel cancels all tasks in the pool.

func (*Pool[T]) CancelOnError

func (p *Pool[T]) CancelOnError() *Pool[T]

CancelOnError enables cancellation of remaining tasks on failure.

func (*Pool[T]) Cause

func (p *Pool[T]) Cause() error

Cause returns the reason for the cancellation of the pool's context. It retrieves the underlying cause of the context's termination if the context has been canceled. If the pool's context is still active, it returns nil.

func (*Pool[T]) ClearMetrics

func (p *Pool[T]) ClearMetrics()

ClearMetrics resets both total tasks and failed tasks counters to zero.

func (*Pool[T]) Context

func (p *Pool[T]) Context(ctx context.Context) *Pool[T]

Context replaces the pool’s context with the provided context. If ctx is nil, context.Background() is used by default.

func (*Pool[T]) FailedTasks

func (p *Pool[T]) FailedTasks() int

FailedTasks returns the number of tasks that have completed with an error.

func (*Pool[T]) GetContext

func (p *Pool[T]) GetContext() context.Context

GetContext returns the current context associated with the pool.

func (*Pool[T]) Go

func (p *Pool[T]) Go(fn func() Result[T])

Go launches an asynchronous task fn() in its own goroutine.

func (*Pool[T]) Limit

func (p *Pool[T]) Limit(workers int) *Pool[T]

Limit sets the maximum number of concurrently running tasks.

func (*Pool[T]) Reset

func (p *Pool[T]) Reset() error

Reset restores the pool to its initial state: cancels all tasks, clears results and metrics, and creates a new context.

func (*Pool[T]) TotalTasks

func (p *Pool[T]) TotalTasks() int

TotalTasks returns the total number of tasks that have been submitted.

func (*Pool[T]) Wait

func (p *Pool[T]) Wait() SeqResult[T]

Wait waits for all submitted tasks in the pool to finish.

Jump to

Keyboard shortcuts

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