waitmap

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: Apache-2.0 Imports: 2 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 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