waitmap

package
v0.7.5 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type WaitMap

type WaitMap[K comparable, V any] struct {
	sync.Mutex
	// contains filtered or unexported fields
}

WaitMap is a key-value store that enables not only setting and getting values from a map, but also waiting until value for a key becomes available.

func New

func New[K comparable, V any](size int) *WaitMap[K, V]

New creates a new WaitMap.

func (*WaitMap[K, V]) Get

func (w *WaitMap[K, V]) Get(key K) (V, bool)

Get will return the current value for the key, if any.

func (*WaitMap[K, V]) Set

func (w *WaitMap[K, V]) Set(key K, value V)

Set sets the value for a key. If the value already exists, we append it to a list.

func (*WaitMap[K, V]) Wait

func (w *WaitMap[K, V]) Wait(key K) V

Wait will wait until the value for a key becomes available.

func (*WaitMap[K, V]) WaitFor

func (w *WaitMap[K, V]) WaitFor(ctx context.Context, key K) (V, bool)

WaitFor will wait for the value for a key to become available, but no longer than the specified duration.

Jump to

Keyboard shortcuts

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