Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ExecuteGroup ¶
type ExecuteGroup[T any] struct { // contains filtered or unexported fields }
ExecuteGroup runs fallible functions concurrently with a bounded degree of parallelism and streams their results back as rutils.Result values. The zero value is not usable; create one with NewExecuteGroup.
func NewExecuteGroup ¶
func NewExecuteGroup[T any](limit int) *ExecuteGroup[T]
NewExecuteGroup returns an ExecuteGroup that runs at most limit functions concurrently. It panics if limit <= 0.
func (*ExecuteGroup[T]) Go ¶
func (r *ExecuteGroup[T]) Go(fn func() (T, error))
Go schedules fn to run in its own goroutine, blocking the caller until a concurrency slot is free. The (value, error) returned by fn is delivered on the Results channel, so every Go call must eventually be matched by a receive (via Results or IntoSlice) or the worker goroutine will block. Do not call Go after Results/IntoSlice has been called.
func (*ExecuteGroup[T]) IntoSlice ¶
func (r *ExecuteGroup[T]) IntoSlice() ([]T, error)
IntoSlice collects every result, returning the values in completion order. It returns the first error encountered, discarding all values in that case; remaining results are drained in the background so no worker leaks.
Contract: like Results, IntoSlice must be called at most once per group.
func (*ExecuteGroup[T]) Results ¶
func (r *ExecuteGroup[T]) Results() <-chan rutils.Result[T]
Results returns a channel that yields one result per scheduled function and is closed once every worker has finished. The caller must drain it fully, otherwise unfinished workers leak on their send.
Contract: Results must be called at most once per ExecuteGroup. Calling it again panics ("close of closed channel") when the second closer runs.
type MapGroup ¶
type MapGroup[K comparable, T any] struct { // contains filtered or unexported fields }
MapGroup runs functions concurrently with a bounded degree of parallelism and gathers their (key, value) results into a map. The zero value is not usable; create one with NewMapGroup.
func NewMapGroup ¶
func NewMapGroup[K comparable, T any](mapCap int, limit int) *MapGroup[K, T]
NewMapGroup returns a MapGroup whose result map is pre-sized to mapCap and which runs at most limit functions concurrently. It panics if limit <= 0.
func (*MapGroup[K, T]) Collect ¶
Collect blocks until all scheduled functions have returned, then reports the accumulated map together with the joined error of every failed call (nil if all succeeded). The returned map is the group's own map: treat it as owned by the caller and do not schedule more work after Collect.
func (*MapGroup[K, T]) Go ¶
Go schedules fn to run in its own goroutine, blocking the caller until a concurrency slot is free. On success the returned key/value is stored; on error the value is dropped and the error is accumulated (see Collect). A later write to the same key overwrites the earlier one.
type WaitGroupWithLimit ¶
type WaitGroupWithLimit struct {
// contains filtered or unexported fields
}
WaitGroupWithLimit is a sync.WaitGroup that caps the number of simultaneously running goroutines. The zero value is not usable; create one with NewSemWaitGroup.
func NewSemWaitGroup ¶
func NewSemWaitGroup(limit int) *WaitGroupWithLimit
NewSemWaitGroup returns a WaitGroupWithLimit that runs at most limit goroutines concurrently. It panics if limit <= 0.
func (*WaitGroupWithLimit) Go ¶
func (r *WaitGroupWithLimit) Go(fn func())
Go schedules fn to run in its own goroutine, blocking the caller until a concurrency slot is free (at most limit are in flight at once). A panic in fn propagates on its own goroutine and is not recovered.
func (*WaitGroupWithLimit) Wait ¶
func (r *WaitGroupWithLimit) Wait()
Wait blocks until all scheduled functions have returned.