Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Ring ¶
type Ring struct {
// contains filtered or unexported fields
}
Ring is a classic generic ring buffer on top of a fixed-sized slice. It is thread-safe.
func New ¶
New allocates a new Ring instance, with capacity for count entries. If newf is non-nil, it is called count times to pre-allocate the entries. Metrics are exported with a 'ring_id" label.
func (*Ring) Close ¶
func (r *Ring) Close()
Close closes the ring buffer, and causes all blocked readers/writers to be notified.
func (*Ring) Read ¶
Read copies entries from the internal ring buffer. If block is true, then Read will block until it is able to read at least one entry (or the Ring is closed). Otherwise it will return immediately if there's no entries available for reading. In case entries is of length zero, the call returns immediately. Returns the number of entries read, or -1 if the RingBuf is closed, and a bool indicating if the read blocked.
func (*Ring) Write ¶
Write copies entries to the internal ring buffer. If block is true, then Write will block until it is able to write at least one entry (or the Ring is closed). Otherwise it will return immediately if there's on space left for writing. In case entries is of length zero, the call returns immediately. Returns the number of entries written, or -1 if the RingBuf is closed, and a bool indicating if the write blocked.