Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrBufferFull is returned when the buffer is full ErrBufferFull = errors.New("bufpipe: buffer is full") // ErrClosedPipe is returned when the pipe is closed ErrClosedPipe = errors.New("bufpipe: closed pipe") // ErrFirstReadTimeout is returned when the pipe is set to block writes until the first read, but the timeout is reached ErrFirstReadTimeout = errors.New("bufpipe: write blocked because first read didn't happen until timeout") )
Functions ¶
func Pipe ¶
func Pipe(options Options) (PipeReader, PipeWriter)
Pipe creates a buffered in-memory pipe. It can be used to connect code expecting an io.Reader with code expecting an io.Writer, but unlike io.Pipe it has internal buffer and can be used to pass data between goroutines without blocking.
Types ¶
type Options ¶
type Options struct {
// MaxSize is the maximum size of the buffer. Write will return ErrBufferFull
// if the buffer is full. If MaxSize is 0, buffer is unlimited. Default is 0.
MaxSize int
// BlockWritesUntilFirstReadTimeout if set to a non-zero value, Write will block until the first Read is called. This is useful
// if you want to make sure that the reader is ready to read before writing to the pipe. Default is false.
BlockWritesUntilFirstReadTimeout time.Duration
// BlockWritesOnFullBufferTimeout if set to a non-zero value, Write will block until the buffer is emptied by some Read() calls.
// This is useful if you want to make sure that the reader has read some data before writing more. Default is no timeout - return ErrBufferFull immediately.
// Only works if MaxSize is set to a non-zero value. If the timeout is reached, Write will return ErrBufferFull
BlockWritesOnFullBufferTimeout time.Duration
}
Click to show internal directories.
Click to hide internal directories.