Documentation
¶
Overview ¶
Package flight collapses concurrent calls for the same key into one execution whose result every caller shares.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Group ¶
type Group[K comparable, V any] struct { // contains filtered or unexported fields }
Group runs at most one call per key at a time. The zero Group is ready.
func (*Group[K, V]) Do ¶
func (g *Group[K, V]) Do(ctx context.Context, key K, fn func(context.Context) (V, error)) (V, error)
Do shares fn among concurrent callers of key. The first caller runs fn on its own goroutine and context, so no work outlives a caller that owns it. Others wait; if the leader's context ended the call, a waiter whose own context is live runs fn itself instead of inheriting that cancellation. Callers share the returned value and must not mutate it.
func (*Group[K, V]) DoDetached ¶
func (g *Group[K, V]) DoDetached(ctx context.Context, key K, fn func(context.Context) (V, error)) (V, error)
DoDetached shares fn among concurrent callers of key. fn runs to completion on its own goroutine with a context that keeps the first caller's values but none of its cancellation, so one caller giving up never fails the others; fn must bound its own work. Every caller, including the first, returns ctx.Err() as soon as its context ends. Callers share the returned value and must not mutate it.