sharedbuffer

package
v0.0.0-...-d00ee4e Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2015 License: MIT Imports: 4 Imported by: 2

Documentation

Overview

SharedBuffer reader. What to know when creating such a reader:

  1. Timeless access to all present and future buffer data
  2. Close() must be called when it's done
  3. 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

View Source
var (
	ErrClosedBuffer = errors.New("cannot write to closed buffer")
	ErrLateReader   = errors.New("cannot create new reader starting at flushed offset")
)
View Source
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 New

func New() *SharedBuffer

New creates an initialized SharedBuffer

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

func (*SharedBuffer) Write

func (sb *SharedBuffer) Write(p []byte) (n int, err error)

Write puts data into the open buffer

Jump to

Keyboard shortcuts

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