Documentation ¶
Overview ¶
Package nbreader implements a non-blocking io.Reader.
The blockSize defines the buffer size that is used to read from the underlying io.Reader.
NBReader allows to specify two timeouts:
Timeout: Read() returns after the specified timeout, even if no data has been read.
ChunkTimeout: Read() returns if no data has been read for the specified time, even if the overall timeout has not been hit yet.
ChunkTimeout must be smaller than Timeout.
Example Usage:
// Create a NBReader that immediately returns on Read(), whether any data has been read or not nbr := nbreader.NewNBReader(reader, 1 << 16) // Create a NBReader that tries to return on Read() after no data has been read for 200ms // or when the maximum timeout of 2 seconds is hit. nbr := nbreader.NewNBReader(reader, 1 << 16, nbreader.Timeout(2000 * time.Millisecond), nbreader.ChunkTimeout(200 * time.Millisecond))
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type NBReader ¶
type NBReader struct {
// contains filtered or unexported fields
}
NBReader implements a non-blocking io.Reader.
func NewNBReader ¶
NewNBReader returns a new NBReader with the given block size.
type Option ¶
type Option func(r *NBReader)
Option implements options that can be passed to NewNBReader.
func ChunkTimeout ¶
ChunkTimeout allows to set the timeout after which the end of a chunk of data is assumed and the read data is returned by Read().