Documentation
¶
Index ¶
- Variables
- type Reader
- type Writer
- func (w *Writer[T]) Append(values ...T) (int, error)
- func (w *Writer[T]) BlockingCurrentReader() *Reader[T]
- func (w *Writer[T]) BlockingReader() *Reader[T]
- func (w *Writer[T]) Close() error
- func (w *Writer[T]) Reader() *Reader[T]
- func (w *Writer[T]) Size() int64
- func (w *Writer[T]) TotalWritten() int64
- func (w *Writer[T]) Write(values []T) (int, error)
Constants ¶
This section is empty.
Variables ¶
var (
ErrStaleReader = errors.New("ringbuffer reader is stale (didn't read fast enough - do you need a larger buffer?)")
)
Functions ¶
This section is empty.
Types ¶
type Reader ¶
type Reader[T any] struct { // contains filtered or unexported fields }
func (*Reader[T]) Close ¶
Close signals this reader will not be used anymore and has finished processing, and should be called after a reader is not useful anymore.
If using Writer.Close then calling Close on readers is mandatory, failing to do so will cause a deadlock.
func (*Reader[T]) Read ¶
Read will read data from the ringbuffer to the provided buffer. If no new data is available, Read() will either return io.EOF (a later call may return new data), or block until data becomes available (if set blocking).
func (*Reader[T]) Reset ¶
func (r *Reader[T]) Reset()
Reset sets the reader's position after the writer's latest write.
func (*Reader[T]) SetAutoSkip ¶
SetAutoSkip allows enabling auto skip, when this reader hasn't been reading fast enough and missed some data. This is generally unsafe, but in some cases may be useful to avoid having to handle stale readers.
type Writer ¶
type Writer[T any] struct { // contains filtered or unexported fields }
Writer is the main data container.
func (*Writer[T]) BlockingCurrentReader ¶ added in v0.1.1
BlockingCurrentReader returns a new reader positionned at the buffer's edge.
func (*Writer[T]) BlockingReader ¶
BlockingReader returns a new reader positioned at the buffer's oldest available position which reads will block if no new data is available.
func (*Writer[T]) Close ¶
Close will cause all readers to return EOF once they have read the whole buffer and will wait until all readers have called Close(). If you do not need EOF synchronization you can ignore the whole close system as it is not used to free any resources, but if you use ringbuf as an output buffer, for example, it will enable waiting for writes to have completed prior to ending the program.
Note that if any reader failed to call close prior to end and being freed this may cause a deadlock. Use CloseNow() to avoid this.
func (*Writer[T]) Reader ¶
Reader returns a new reader positioned at the buffer's oldest available position. The reader can be moved to the most recent position by calling its Reset() method.
If there isn't enough data to read, the reader's read method will return error io.EOF. If you need Read() to not return until new data is available, use BlockingReader()