evictch

package
v0.1.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package evictch contains an implementation of a buffered channel with the ability to evict old entries once the channel is filled entirely.

Note: the current implementation supports only 1 reader and 1 writer running concurrently.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chan

type Chan[T any] struct {
	// contains filtered or unexported fields
}

Chan is an implementation of a buffered channel with automatic eviction of oldest entries.

func NewChan

func NewChan[T any](capacity uint) *Chan[T]

NewChan constructs a new buffered channel with eviction. A maximum of capacity elements will be retained. Note that capacity must be greater than 0, as the whole idea of such a channel is to allow write operations which will not wait for a reader to arrive.

func (*Chan[T]) Close

func (ch *Chan[T]) Close()

Close closes the channel. This should be called after the writer is finished writing.

func (*Chan[T]) Read

func (ch *Chan[T]) Read() (T, bool)

Read reads a value from the channel. If one is available in the buffer, it is instantly chosen, otherwise, Read waits for a Write using sync.Cond.

func (*Chan[T]) Write

func (ch *Chan[T]) Write(v T)

Write writes a new value to the buffered channel. If it is already full, the oldest (so, the head of the queue) element is removed first, to meet the expected channel capacity.

Jump to

Keyboard shortcuts

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