Skip to content

andys/genringbuffer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

genringbuffer

import "github.com/andys/genringbuffer"

Index

type Ringbuffer

Ringbuffer is a fixed length FIFO queue that drops new items when full and allows non-blocking polling for new items with optional timeout

type Ringbuffer[T any] chan T

func NewRingBuffer

func NewRingBuffer[T any](size int) Ringbuffer[T]

NewRingbuffer creates a new ringbuffer with the given fixed number of items.

func (Ringbuffer[T]) Cap

func (r Ringbuffer[T]) Cap() int

Cap returns the capacity of the ringbuffer.

func (Ringbuffer[T]) Close

func (r Ringbuffer[T]) Close()

Close closes the ringbuffer.

func (Ringbuffer[T]) Get

func (r Ringbuffer[T]) Get() T

Get gets an item from the ringbuffer, or blocks until one is available.

func (Ringbuffer[T]) Len

func (r Ringbuffer[T]) Len() int

Len returns the number of items in the ringbuffer.

func (Ringbuffer[T]) Offer

func (r Ringbuffer[T]) Offer(input T) bool

Offer adds an item to the ringbuffer. If the buffer is full, it returns immediately. Returns true if added.

func (Ringbuffer[T]) Poll

func (r Ringbuffer[T]) Poll(dur time.Duration) (obj T, res bool)

Poll gets an item from the ringbuffer, or blocks until one is available, until dur duration passed. Returns true if an item was returned.

Generated by gomarkdoc

About

Fixed-length FIFO queue for Go Generics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages