concurrency

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2026 License: 0BSD Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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]) Get

func (c *Cache[K, V]) Get(key K) (Entry[V], bool)

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.

func (*Cache[K, V]) InvalidateIfCurrent

func (c *Cache[K, V]) InvalidateIfCurrent(key K, entry Entry[V])

func (*Cache[K, V]) Set

func (c *Cache[K, V]) Set(key K, value V, expiry time.Time) Entry[V]

Set replaces an entry. A zero expiry keeps it eligible until eviction or invalidation.

type Entry

type Entry[V any] struct {
	Value V
	// contains filtered or unexported fields
}

Entry identifies one publication. Copies retain its identity.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL