durationstore

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Greater

func Greater(oldDur, newDur time.Duration) bool

func Less

func Less(oldDur, newDur time.Duration) bool

Types

type DurationStore

type DurationStore struct {
	// Underlying data store
	sync.Map
	// contains filtered or unexported fields
}

DurationStore{} stores arbitrary time.Duration. It allows for safe pushes and pops based on any arbitrary keys.

func NewDurationStore

func NewDurationStore(eval func(oldDur, newDur time.Duration) bool) *DurationStore

NewDurationStore() returns a duration store which will evaluate which value to keep, when multiple are pushed to the same key, based on the eval() function.

func (*DurationStore) Peek

func (dm *DurationStore) Peek(key string) time.Duration

Peek() will return the duration stored by the key and *not* delete the store. If no duration was stored for that key, then 0 will be returned.

func (*DurationStore) Pop

func (dm *DurationStore) Pop(key string) time.Duration

Pop() will return the duration stored by the key and delete the store. If no duration was stored for that key, then 0 will be returned.

func (*DurationStore) Push

func (dm *DurationStore) Push(key string, newDur time.Duration)

Push() will store a duration for the key. If multiple values are pushed onto the same key before the key is popped, then the one that returns true from DurationStore.eval() is kept.

Jump to

Keyboard shortcuts

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