waitmap

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: Apache-2.0 Imports: 2 Imported by: 0 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type WaitMap

type WaitMap 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. Important: Since this implementation is tied pretty closely to how it will be used, (as an internal package), it has the peculiar behavior of only the first `Set` setting the value. Subsequent `Sets()` are recorded, but don't change the returned value.

func New

func New() *WaitMap

New creates a new WaitMap.

func (*WaitMap) Get

func (w *WaitMap) Get(key string) (any, bool)

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

func (*WaitMap) Set

func (w *WaitMap) Set(key string, value any)

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

func (*WaitMap) Wait

func (w *WaitMap) Wait(key string) any

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

func (*WaitMap) WaitFor

func (w *WaitMap) WaitFor(ctx context.Context, key string) (any, 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