async

package
v0.7.5 Latest Latest
Warning

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

Go to latest
Published: May 21, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Collect

func Collect[T any](ch <-chan T) []T

Collect drains a channel into a slice. Blocks until the channel is closed.

func Map

func Map[In, Out any](ctx context.Context, p *Pool, items []In, fn func(context.Context, In) (Out, bool)) <-chan Out

Map fans out work across the pool and returns a channel of results. Channel is closed when all items are processed.

Types

type Pool

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

Pool is a fixed-size worker pool. N goroutines are started at creation and pull work from an internal channel. Submit never blocks unless the queue is full — and the queue is buffered to queueSize.

func NewPool

func NewPool(n int, queueSize int) *Pool

NewPool creates a pool with n persistent workers and a buffered work queue. If queueSize <= 0 it defaults to n*4.

func NewPoolContext

func NewPoolContext(ctx context.Context, n int, queueSize int) *Pool

NewPoolContext creates a pool with n persistent workers and a buffered work queue. If queueSize <= 0 it defaults to n*4.

func (*Pool) Close

func (p *Pool) Close()

Close stops all workers after draining the queue. Blocks until all workers exit.

func (*Pool) Kill

func (p *Pool) Kill()

Kill stops all workers immediately without draining.

func (*Pool) Submit

func (p *Pool) Submit(ctx context.Context, fn func()) error

Submit enqueues work. Non-blocking if queue has capacity. Returns ctx.Err() if context expires while waiting for a slot.

Jump to

Keyboard shortcuts

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