blocking_fifo

package module
v0.0.0-...-8085911 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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.

func (*BlockingFIFO) Write

func (b *BlockingFIFO) Write(p []byte) (int, error)

Write writes a chunk of data to the buffer. This function never blocks.

Jump to

Keyboard shortcuts

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