rbuffer

package
v3.16.11 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("buffer closed")

Functions

This section is empty.

Types

type RingBuffer

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

RingBuffer is a bounded, concurrent-safe byte buffer that applies backpressure on Write when full instead of overwriting unread data.

Semantics:

  • Write blocks until all bytes in p have been written, or until Close is called (in which case it returns ErrClosed with the count written so far). It never discards unread data.
  • Read blocks until at least one byte is available or the buffer is closed and drained (in which case it returns io.EOF).
  • Close wakes all blocked readers and writers; subsequent Writes return ErrClosed, Reads return any remaining data then io.EOF.

func NewRingBuffer

func NewRingBuffer(size int) *RingBuffer

func (*RingBuffer) Close

func (b *RingBuffer) Close() error

func (*RingBuffer) Read

func (b *RingBuffer) Read(p []byte) (int, error)

Read blocks until at least one byte is available, the buffer is closed and drained, or p is empty.

func (*RingBuffer) Reset

func (b *RingBuffer) Reset()

func (*RingBuffer) Write

func (b *RingBuffer) Write(p []byte) (int, error)

Write blocks until all of p has been written, applying backpressure when the buffer is full instead of discarding unread data. If Close is called while Write is blocked, it returns ErrClosed along with the number of bytes successfully written so far.

Jump to

Keyboard shortcuts

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