Documentation
¶
Index ¶
- func All(ctx context.Context, fns ...func(context.Context) error) error
- func Fire(fn func())
- func Map[T, R any](ctx context.Context, items []T, fn func(context.Context, T) (R, error)) ([]R, error)
- func Settle(ctx context.Context, fns ...func(context.Context) error) []error
- type Group
- type GroupMetrics
- type GroupOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func All ¶
All runs fns concurrently and returns the first error (or nil). First error cancels remaining work via a derived context. Functions capture output via closures to pre-declared outer variables. Panics are recovered and converted to errors.
func Fire ¶
func Fire(fn func())
Fire spawns a goroutine with panic recovery. Panics logged to slog.Default().
func Map ¶
func Map[T, R any](ctx context.Context, items []T, fn func(context.Context, T) (R, error)) ([]R, error)
Map applies fn to every item concurrently and returns results in order. First error cancels remaining work. Panics are recovered and converted to errors.
Types ¶
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group manages fire-and-forget goroutines with panic recovery.
func NewGroup ¶
func NewGroup(opts ...GroupOption) *Group
NewGroup creates a Group with the given options.
type GroupMetrics ¶
type GroupMetrics interface {
Blocked() // semaphore contention occurred (fired after the wait completes)
Dispatched(blocked time.Duration) // job accepted; worker goroutine about to spawn (blocked=0 if no wait)
Completed(duration time.Duration) // job finished without panic recovery
Panicked(duration time.Duration) // job finished via panic recovery
}
GroupMetrics receives lifecycle callbacks from Group.Go.
Every Dispatched call is followed by exactly one Completed or Panicked call. Blocked fires at most once per Dispatched, immediately before it. No callbacks fire for calls to Go after Close (true no-op).
WARNING: callbacks run synchronously on the Group hot path and during worker teardown. They are not isolated in a separate goroutine. Implementations must be safe for concurrent use, must not block, must not perform slow I/O, and must not panic. A bad implementation can stall Go(), delay or deadlock Close(), and hold semaphore slots longer than expected.
type GroupOption ¶
type GroupOption func(*Group)
GroupOption configures a Group.
func WithGroupLogger ¶
func WithGroupLogger(l *slog.Logger) GroupOption
WithGroupLogger sets the logger for panic recovery output.
func WithLimit ¶
func WithLimit(n int) GroupOption
WithLimit caps concurrent goroutines via a semaphore. Values less than 1 are clamped to 1.
func WithMetrics ¶
func WithMetrics(m GroupMetrics) GroupOption
WithMetrics sets the metrics observer for Group lifecycle events. See GroupMetrics for the synchronous callback warning and constraints.