expiring

package
v0.0.0-...-7df4f84 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type List

type List struct {
	// contains filtered or unexported fields
}

List tracks elements along with their creation times. This is essentially a linked list with timestamp on each entry, allowing dropping old entries. This struct is not thread safe. TODO(x13n): Migrate to generics once supported by Go stdlib (container/list in particular).

func NewList

func NewList() *List

NewList creates a new expiring list.

func (*List) DropNotNewerThan

func (e *List) DropNotNewerThan(expiry time.Time)

DropNotNewerThan removes all elements of the list that are older or exactly as old as the provided time.

func (*List) RegisterElement

func (e *List) RegisterElement(elem interface{})

RegisterElement adds new element to the list.

func (*List) ToSlice

func (e *List) ToSlice() []interface{}

ToSlice converts the underlying list of elements into a slice.

func (*List) ToSliceWithTimestamp

func (e *List) ToSliceWithTimestamp() ([]interface{}, time.Time)

ToSliceWithTimestamp is identical to ToSlice, but additionally returns the timestamp of newest entry (or current time if there are no entries).

Jump to

Keyboard shortcuts

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