genringbuffer

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2022 License: MIT Imports: 1 Imported by: 0

README

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ringbuffer

type Ringbuffer[T any] chan T

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

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.

Jump to

Keyboard shortcuts

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