Documentation
¶
Index ¶
- Variables
- type BlockingFIFO
- func (b *BlockingFIFO) CancelAllReads()
- func (b *BlockingFIFO) Close() error
- func (b *BlockingFIFO) CloseRead() error
- func (b *BlockingFIFO) CloseWrite() error
- func (b *BlockingFIFO) Len() int
- func (b *BlockingFIFO) Read(p []byte) (int, error)
- func (b *BlockingFIFO) SetBlockOnShortage(v bool)
- func (b *BlockingFIFO) Write(p []byte) (int, error)
Constants ¶
This section is empty.
Variables ¶
var ErrOperationCanceled = fmt.Errorf("operation canceled")
Functions ¶
This section is empty.
Types ¶
type BlockingFIFO ¶
type BlockingFIFO struct {
// contains filtered or unexported fields
}
BlockingFIFO represents a FIFO buffer that implements both io.Writer and io.Reader interface. A BlockingFIFO can have multiple writers and readers, and consumer will block if no sufficient data are provided by the writers.
func (*BlockingFIFO) CancelAllReads ¶
func (b *BlockingFIFO) CancelAllReads()
CancelAllReads cancels all the pending readers and let them return immediately with zero-length read and ErrOperationCanceled.
func (*BlockingFIFO) Close ¶
func (b *BlockingFIFO) Close() error
Close effectively prevents future reads and writes.
func (*BlockingFIFO) CloseRead ¶
func (b *BlockingFIFO) CloseRead() error
CloseRead flags the FIFO so that it no longer accepts reads from it. The method also instruct it to fulfill the pending reads with the remaining data in the buffer. Any further read attempts will fail with io.EOF.
func (*BlockingFIFO) CloseWrite ¶
func (b *BlockingFIFO) CloseWrite() error
CloseWrite flags the FIFO so that it no longer accepts writes to it. Any further write attempts will fail with errors.
func (*BlockingFIFO) Len ¶
func (b *BlockingFIFO) Len() int
Len returns the total size of data in the buffer.
func (*BlockingFIFO) Read ¶
func (b *BlockingFIFO) Read(p []byte) (int, error)
Read enqueues a read request with the specified amount of data, and wait until the request is fulfilled for an indefinite time if the FIFO is set to blocking mode. If it is not set so, the function returns immediately with the data in the buffer, or zero-length read.
func (*BlockingFIFO) SetBlockOnShortage ¶
func (b *BlockingFIFO) SetBlockOnShortage(v bool)
SetBlockOnShortage marks the FIFO so that read attempts will block when the data in the buffer is insufficient to fulfill the read requests.