Documentation
¶
Index ¶
- Variables
- type RingBuffer
- type UnboundedChan
- func (c *UnboundedChan[T]) BufCapacity() int
- func (c *UnboundedChan[T]) BufLen() int
- func (c *UnboundedChan[T]) Discards() uint64
- func (c *UnboundedChan[T]) Len() int
- func (c *UnboundedChan[T]) MaxBufferSize() int
- func (c *UnboundedChan[T]) SetMaxBufferSize(n int) int
- func (c *UnboundedChan[T]) SetOnDiscards(fn func(T))
Constants ¶
This section is empty.
Variables ¶
var ErrIsEmpty = errors.New("ringbuffer is empty")
Functions ¶
This section is empty.
Types ¶
type RingBuffer ¶
type RingBuffer[T any] struct { // contains filtered or unexported fields }
RingBuffer is a ring buffer for common types. It never is full and always grows if it will be full. It is not thread-safe(goroutine-safe) so you must use the lock-like synchronization primitive to use it in multiple writers and multiple readers.
func NewRingBuffer ¶
func NewRingBuffer[T any](initialSize int) *RingBuffer[T]
func (*RingBuffer[T]) Capacity ¶
func (r *RingBuffer[T]) Capacity() int
Capacity returns the size of the underlying buffer.
func (*RingBuffer[T]) IsEmpty ¶
func (r *RingBuffer[T]) IsEmpty() bool
func (*RingBuffer[T]) Len ¶
func (r *RingBuffer[T]) Len() int
func (*RingBuffer[T]) Peek ¶
func (r *RingBuffer[T]) Peek() T
func (*RingBuffer[T]) Pop ¶
func (r *RingBuffer[T]) Pop() T
func (*RingBuffer[T]) Read ¶
func (r *RingBuffer[T]) Read() (T, error)
func (*RingBuffer[T]) Reset ¶
func (r *RingBuffer[T]) Reset()
func (*RingBuffer[T]) Write ¶
func (r *RingBuffer[T]) Write(v T)
type UnboundedChan ¶
type UnboundedChan[T any] struct { In chan<- T // channel for write Out <-chan T // channel for read // contains filtered or unexported fields }
UnboundedChan is an unbounded chan. In is used to write without blocking, which supports multiple writers. and Out is used to read, which supports multiple readers. You can close the in channel if you want.
func NewUnboundedChan ¶
func NewUnboundedChan[T any](ctx context.Context, initCapacity int, maxBufferSize ...int) *UnboundedChan[T]
NewUnboundedChan creates the unbounded chan. in is used to write without blocking, which supports multiple writers. and out is used to read, which supports multiple readers. You can close the in channel if you want.
func NewUnboundedChanSize ¶ added in v0.0.103
func NewUnboundedChanSize[T any](ctx context.Context, initInCapacity, initOutCapacity, initBufCapacity int, maxBufferSize ...int) *UnboundedChan[T]
NewUnboundedChanSize is like NewUnboundedChan but you can set initial capacity for In, Out, Buffer. and max buffer capactiy.
func (*UnboundedChan[T]) BufCapacity ¶ added in v0.0.104
func (c *UnboundedChan[T]) BufCapacity() int
BufCapacity returns capacity of the buffer.
func (*UnboundedChan[T]) BufLen ¶
func (c *UnboundedChan[T]) BufLen() int
BufLen returns len of the buffer. It is not accurate and only for your evaluating approximate number of elements in this chan, see https://github.com/smallnest/chanx/issues/7.
func (*UnboundedChan[T]) Discards ¶ added in v0.0.104
func (c *UnboundedChan[T]) Discards() uint64
Discards returns the number of discards.
func (*UnboundedChan[T]) Len ¶
func (c *UnboundedChan[T]) Len() int
Len returns len of In plus len of Out plus len of buffer. It is not accurate and only for your evaluating approximate number of elements in this chan, see https://github.com/smallnest/chanx/issues/7.
func (*UnboundedChan[T]) MaxBufferSize ¶ added in v1.1.1
func (c *UnboundedChan[T]) MaxBufferSize() int
MaxBufferSize returns maximum capacity of the buffer.
func (*UnboundedChan[T]) SetMaxBufferSize ¶ added in v1.1.1
func (c *UnboundedChan[T]) SetMaxBufferSize(n int) int
SetMaxBufferSize reset the maximum capacity of buffer 0 or negative means unlimited
func (*UnboundedChan[T]) SetOnDiscards ¶ added in v1.1.0
func (c *UnboundedChan[T]) SetOnDiscards(fn func(T))
SetOnDiscards set the callback function when data is discarded
