Documentation ¶
Overview ¶
SharedBuffer reader. What to know when creating such a reader:
- Timeless access to all present and future buffer data
- Close() must be called when it's done
- Will return a EOF after the buffer is closed and all data has been read
sharedbuffer provides a buffer which supports concurrent access by multiple readers.
The buffer automatically flushes any data which has been read by all readers. To create a reader, simply call sb.NewReader(), given a SharedBuffer sb. If a consumer is done with the buffer, it must signal so by closing its reader. If a reader is not closed, the buffer will not flush any data past the unused reader's position!
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrClosedBuffer = errors.New("cannot write to closed buffer") ErrLateReader = errors.New("cannot create new reader starting at flushed offset") )
var ErrClosedReader = errors.New("closed reader")
Functions ¶
This section is empty.
Types ¶
type SharedBuffer ¶
type SharedBuffer struct {
// contains filtered or unexported fields
}
SharedBuffer represents a concurrently shared buffer
func (*SharedBuffer) Close ¶
func (sb *SharedBuffer) Close() error
Close the buffer, preventing any further writes. Readers will return io.EOF after consuming the remainder.
func (*SharedBuffer) NewReader ¶
func (sb *SharedBuffer) NewReader() io.ReadCloser
NewReader creates a registered reader for the buffer. This reader must be closed when it is done, lest you hate having free memory.
func (*SharedBuffer) NewReaderAt ¶
func (sb *SharedBuffer) NewReaderAt(off int64) (io.ReadCloser, error)
NewReaderAt generates a registered reader which will block until the buffer fills to the given offset