Documentation ¶
Index ¶
Constants ¶
const ( Capacity1 capacity = 1<<(iota+1) - 1 Capacity3 Capacity7 Capacity15 Capacity31 Capacity63 Capacity127 Capacity255 Capacity511 Capacity1023 Capacity2047 Capacity4095 Capacity8191 Capacity16383 Capacity32767 Capacity65535 )
CapacityN represent possible buffer capacities for Ring where N is the actual capacity.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Capacity ¶
type Capacity interface { // Cap returns the actual capacity. Cap() capacity // AsInt returns the actual capacity as an int. AsInt() int }
Capacity is the interface that wraps Cap.
func NewCapacity ¶
NewCapacity creates a new Capacity from n. The value of n MUST satisfy n=2^i -1 for i = [1, 16]; ie:
1, 3, 7, ..., 2047, 4095, ..., 65535
Constants CapacityN represent all possible values of n and are valid Capacity that can be provided to NewRing.
type Ring ¶
type Ring struct {
// contains filtered or unexported fields
}
Ring is a ring buffer that stores *v1.Event
func (*Ring) LastWrite ¶
LastWrite returns the last element written. Note: If Write(*v1.Event) is being executed concurrently with Read(uint64) please use LastWriteParallel instead.
func (*Ring) LastWriteParallel ¶
LastWriteParallel returns the last element written.
func (*Ring) Len ¶
Len returns the number of elements in the ring buffer, similar to builtin `len()`.
func (*Ring) OldestWrite ¶
OldestWrite returns the oldest element written. Note: It should only be used to read from the beginning of the buffer.
type RingReader ¶
type RingReader struct {
// contains filtered or unexported fields
}
RingReader is a reader for a Ring container.
func NewRingReader ¶
func NewRingReader(ring *Ring, start uint64) *RingReader
NewRingReader creates a new RingReader that starts reading the ring at the position given by start.
func (*RingReader) Close ¶
func (r *RingReader) Close() error
Close waits for any spawned go routines to finish. It is not required to call Close on a RingReader but it may be useful for specific situations such as testing. Must not be called concurrently with NextFollow, as otherwise NextFollow spawns new go routines that are not waited on.
func (*RingReader) Next ¶
func (r *RingReader) Next() (*v1.Event, error)
Next reads the event at the current position and increment the read position. Returns io.EOF if there are no more entries. May return ErrInvalidRead if the writer overtook this RingReader.
func (*RingReader) NextFollow ¶
func (r *RingReader) NextFollow(ctx context.Context) *v1.Event
NextFollow reads the event at the current position and increment the read position by one. If there are no more event to read, NextFollow blocks until the next event is added to the ring or the context is cancelled.