chunkbuffer

package
v0.9.43 Latest Latest
Warning

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

Go to latest
Published: May 23, 2026 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 Buffer

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

Buffer is a thread-safe buffer for accumulating stream chunks. It serves as the single source of truth for both live streaming preview and final persistence, eliminating duplicate storage.

The buffer supports:

  • Append: adding new chunks from the streaming goroutine
  • Slice: reading all chunks for final persistence

func New

func New() *Buffer

New creates a new Buffer.

func (*Buffer) Append

func (b *Buffer) Append(chunk *httpclient.StreamEvent) bool

Append adds a chunk to the buffer. It is safe to call from the streaming goroutine. Returns false if the buffer is closed.

func (*Buffer) At

func (b *Buffer) At(index int) (*httpclient.StreamEvent, bool)

At returns the chunk at index when present.

func (*Buffer) Close

func (b *Buffer) Close()

Close marks the buffer as closed, preventing further appends.

func (*Buffer) IsClosed

func (b *Buffer) IsClosed() bool

IsClosed returns true if the buffer is closed.

func (*Buffer) LastAppendedAt

func (b *Buffer) LastAppendedAt() time.Time

LastAppendedAt returns the timestamp of the last successfully appended chunk.

func (*Buffer) Len

func (b *Buffer) Len() int

Len returns the current number of chunks in the buffer.

func (*Buffer) Read

func (b *Buffer) Read(index int) (*httpclient.StreamEvent, int, bool, bool)

Read returns the chunk at index when present, along with the next index and whether the buffer was closed at the same instant the read was performed.

func (*Buffer) Slice

func (b *Buffer) Slice() []*httpclient.StreamEvent

Slice returns a copy of all chunks in the buffer.

func (*Buffer) SubscribeFromCurrent

func (b *Buffer) SubscribeFromCurrent() (<-chan struct{}, int, func())

SubscribeFromCurrent registers a subscriber and atomically returns the current buffer length as the replay cutoff for that subscriber.

Jump to

Keyboard shortcuts

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