Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContextIsDone ¶
ContextIsDone returns true if the supplied context is reporting that it is done.
func GetShuffledIntList ¶
GetShuffledIntList returns a list of contiguous sudo-randomly shuffled integers n, where n[i] is in [1, size].
func PanicIfNil ¶
func PanicIfNil(items ...interface{})
PanicIfNil will panic if any of the supplied items is nil.
Types ¶
type BackoffAPI ¶
type BackoffAPI interface { Wait() error Reset() }
type ConstantBackoff ¶
type ConstantBackoff struct {
// contains filtered or unexported fields
}
func NewConstantBackoff ¶
func NewConstantBackoff(ctx context.Context, rate, maxCumulativeWait time.Duration) *ConstantBackoff
func (*ConstantBackoff) Reset ¶
func (cb *ConstantBackoff) Reset()
func (*ConstantBackoff) Wait ¶
func (cb *ConstantBackoff) Wait() error
type FrameScanner ¶
type FrameScanner struct {
// contains filtered or unexported fields
}
FrameScanner provides methods for scanning a reader that returns records that are prefixed with a big endian int32 that describes the length of the message to follow.
func NewFrameScanner ¶
func NewFrameScanner(reader io.Reader, backoff BackoffAPI) *FrameScanner
NewFrameScanner instantiates a new FrameScanner that can poll the supplied reader. Backoff is used to apply pacing, context cancellation, and bailout behavior in case the reader is misbehaving. For more details, see Poll().
func (*FrameScanner) Err ¶
func (fs *FrameScanner) Err() error
Err returns any errors returned from the Scanner or its underlaying reader. Err will be nil if the reader is closed and scanning completes successfully.
func (*FrameScanner) Poll ¶
func (fs *FrameScanner) Poll() <-chan []byte
Poll begins polling the underlaying reader, and sends complete records to a returned channel. This continues until the underlaying reader returns an error, closes (returns io.EOF), or until the underlaying Backoff object's Wait method returns an error. In general, any time the reader is able to successfully read a frame header or record, it will call Backoff.Reset(). However each read attempt that fails to read a full frame header or full record will call Backoff.Wait(), and evaluate whether or not Wait has returned an error. If wait returns an error, Poll will halt immediately, and the error can be evaluated via the Err method.
type LinearBackoff ¶
type LinearBackoff struct {
// contains filtered or unexported fields
}
LinearBackoff provides a means of linearly increasing a wait period after each subsequent call to a Wait method.
func NewLinearBackoff ¶
func NewLinearBackoff(ctx context.Context, increment, maxCumulativeWait time.Duration) *LinearBackoff
NewLinearBackoff initializes a backoff. increment defines the amount to increase the wait duration after each call to Wait. maxCumulativeWait is the maximum amount of total time that Backoff will wait across consecutive calls to Wait before Wait will return an error.
func (*LinearBackoff) Reset ¶
func (lb *LinearBackoff) Reset()
Reset returns LinearBackoff to its initial state. Restoring the cumulative wait time to zero, and the current wait period back to zero.
func (*LinearBackoff) Wait ¶
func (lb *LinearBackoff) Wait() error
Wait blocks for a period of time. The duration of the wait period increases linearly with each call to Wait. The initial blocking period is always zero, so only the second and subsequent calls to Wait effectively block. If the total time spent waiting would exceed the maximum cumulative wait duration, the method does not block, and instead immediately returns an error. Context cancellation is given higher priority than the current wait period. Thus, if the parent context is cancelled before the current wait period is complete, the method will immediately return a "parent context done" error. When Wait returns an error, it should not be called again unless the Reset method is called first. Calling the Wait method after it has returned an error but without first calling Reset is undefined, and may produce undesirable results.