Documentation ¶
Overview ¶
Package singleflight implements a call sharing mechanism.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Caller ¶
type Caller[K comparable, V any] struct { // contains filtered or unexported fields }
Caller wraps the functionality of the call sharing mechanism.
A Caller must not be copied after first use.
func (*Caller[K, V]) Call ¶
func (caller *Caller[K, V]) Call(ctx context.Context, key K, fn func(context.Context) (V, error)) (V, error)
Call calls fn and returns the results. Concurrent callers sharing a key will also share the results of the first call.
fn may access the key passed to Call via KeyFromContext.
func (*Caller[K, V]) KeyFromContext ¶
KeyFromContext returns the key ctx carries. It panics in case ctx carries no key.
Click to show internal directories.
Click to hide internal directories.