Documentation
¶
Overview ¶
Package flight runs one call per key at a time and hands its result to every caller that asked while it ran, the way golang.org/x/sync/singleflight does, with each caller's context kept:
- A call runs with the context of the caller that started it.
- A caller stops waiting as soon as its own context ends; the call goes on for the others.
- When a call ends because the context of the caller that started it ended, a caller still waiting does not take that as its answer: it starts the call again, under its own context.
- A call that panics makes every caller waiting for it panic, each on its own goroutine, with a *PanicError, so whatever recovers a caller's panic recovers this one. The process is never brought down from a goroutine no caller owns.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Group ¶
type Group[T any] struct { // contains filtered or unexported fields }
Group runs calls that return a T, one per key at a time. The zero Group is ready to use, and a Group must not be copied after first use.
func (*Group[T]) Do ¶
func (g *Group[T]) Do(ctx context.Context, key string, fn func(context.Context) (T, error)) (T, error)
Do runs fn under key with ctx, or waits for the call under key already running, and returns its result. It returns ctx's error as soon as ctx ends, whether or not the call has.
type PanicError ¶
PanicError is what a caller panics with when the call it waited for panicked: the call's panic value and the stack where it happened.
func (*PanicError) Error ¶
func (p *PanicError) Error() string
Error describes the panic with its stack.
func (*PanicError) Unwrap ¶
func (p *PanicError) Unwrap() error
Unwrap returns the panic value when it is an error.