Documentation
¶
Overview ¶
Package concurrency provides state that parallel callbacks can safely share.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache[K comparable, V any] struct { // contains filtered or unexported fields }
Cache synchronizes access to entries. Callers own the safety of native Go keys and values. Its zero value is ready to use. Do not copy a Cache after first use.
func NewCache ¶
func NewCache[K comparable, V any]() *Cache[K, V]
func (*Cache[K, V]) GetOrLoad ¶
func (c *Cache[K, V]) GetOrLoad(ctx context.Context, key K, load func() (V, time.Time, error)) (Entry[V], error)
GetOrLoad runs load synchronously on a miss. Concurrent callers for the same key can cancel their wait independently. A failed or panicking load releases waiters to retry with their own loader. A loader must not wait on its own pending load.