Documentation
¶
Index ¶
- type ProcessFunc
- type RingMPSC
- func (rb *RingMPSC[T]) Capacity() uint64
- func (rb *RingMPSC[T]) Close()
- func (rb *RingMPSC[T]) IsClosed() bool
- func (rb *RingMPSC[T]) IsEmpty() bool
- func (rb *RingMPSC[T]) IsFull() bool
- func (rb *RingMPSC[T]) Length() uint64
- func (rb *RingMPSC[T]) Pop() (T, bool)
- func (rb *RingMPSC[T]) Push(item T) bool
- func (rb *RingMPSC[T]) TryPop() (T, bool)
- func (rb *RingMPSC[T]) TryPush(item T) bool
- type RingMPSCConfig
- type RingSPSC
- func (rb *RingSPSC[T]) Capacity() uint64
- func (rb *RingSPSC[T]) Close()
- func (rb *RingSPSC[T]) IsClosed() bool
- func (rb *RingSPSC[T]) IsEmpty() bool
- func (rb *RingSPSC[T]) IsFull() bool
- func (rb *RingSPSC[T]) Length() uint64
- func (rb *RingSPSC[T]) Pop() (T, bool)
- func (rb *RingSPSC[T]) Push(item T) bool
- func (rb *RingSPSC[T]) TryPop() (T, bool)
- func (rb *RingSPSC[T]) TryPush(item T) bool
- type RingSPSCConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ProcessFunc ¶
type ProcessFunc[T any] func(T)
ProcessFunc defines the function signature for processing messages T can be any type: []byte, string, struct, etc.
type RingMPSC ¶
type RingMPSC[T any] struct { // contains filtered or unexported fields }
RingMPSC is a high-performance ring buffer for multiple producers and a single consumer Uses a mutex to serialize concurrent writes from multiple producers
func NewRingMPSC ¶
func NewRingMPSC[T any](cfg RingMPSCConfig[T]) *RingMPSC[T]
NewRingMPSC creates a new MPSC ring buffer with the given configuration
func (*RingMPSC[T]) Close ¶
func (rb *RingMPSC[T]) Close()
Close closes the ring buffer and wakes up blocked consumers After close, producers cannot push new data, but consumers will drain remaining data Safe to call multiple times
func (*RingMPSC[T]) IsEmpty ¶
IsEmpty reports whether the ring buffer contains no items. It suffers from a race condition where the result may be stale immediately after return.
func (*RingMPSC[T]) IsFull ¶
IsFull reports whether the ring buffer is at capacity. It suffers from a race condition where the result may be stale immediately after return.
func (*RingMPSC[T]) Length ¶
Length returns the approximate number of items currently in the buffer. The returned length is approximate and may be stale by the time it's used.
func (*RingMPSC[T]) Pop ¶
Pop reads data by consumer with blocking Blocks and waits until data arrives if buffer is empty Returns the data and success flag (false indicates closed AND buffer is empty) When closed, will drain all remaining data before returning false
func (*RingMPSC[T]) Push ¶
Push writes data by producer with blocking Blocks and waits until space is available if buffer is full Returns false if ring buffer is closed, true on success
type RingMPSCConfig ¶
type RingMPSCConfig[T any] struct { // Capacity is the buffer size of the ring buffer // Default: 1024 Capacity uint64 // ProcessFunc is the function to process each message // Optional: if provided, a consumer goroutine will be automatically started // If nil, you need to manually call Pop() to consume messages ProcessFunc ProcessFunc[T] }
RingMPSCConfig holds configuration for RingMPSC T is the type of messages being processed
type RingSPSC ¶
type RingSPSC[T any] struct { // contains filtered or unexported fields }
RingSPSC is a lock-free ring buffer for single producer and single consumer Implements high-performance SPSC queue using atomic operations, ensuring strict FIFO ordering
func NewRingSPSC ¶
func NewRingSPSC[T any](cfg RingSPSCConfig[T]) *RingSPSC[T]
NewRingSPSC creates a new SPSC ring buffer with the given configuration
func (*RingSPSC[T]) Close ¶
func (rb *RingSPSC[T]) Close()
Close closes the ring buffer and wakes up blocked consumers After close, producers cannot push new data, but consumers will drain remaining data Safe to call multiple times
func (*RingSPSC[T]) IsEmpty ¶
IsEmpty reports whether the ring buffer contains no items. It suffers from a race condition where the result may be stale immediately after return.
func (*RingSPSC[T]) IsFull ¶
IsFull reports whether the ring buffer is at capacity. It suffers from a race condition where the result may be stale immediately after return.
func (*RingSPSC[T]) Length ¶
Length returns the approximate number of items currently in the buffer. The returned length is approximate and may be stale by the time it's used.
func (*RingSPSC[T]) Pop ¶
Pop reads data by consumer with blocking Blocks and waits until data arrives if buffer is empty Returns the data and success flag (false indicates closed AND buffer is empty) When closed, will drain all remaining data before returning false
func (*RingSPSC[T]) Push ¶
Push writes data by producer with blocking Blocks and waits until space is available if buffer is full Returns false if ring buffer is closed, true on success This approach ensures data is not lost, forming a backpressure mechanism
type RingSPSCConfig ¶
type RingSPSCConfig[T any] struct { // Capacity is the buffer size of the ring buffer // Default: 1024 Capacity uint64 // ProcessFunc is the function to process each message // Optional: if provided, a consumer goroutine will be automatically started // If nil, you need to manually call Pop() to consume messages ProcessFunc ProcessFunc[T] }
RingSPSCConfig holds configuration for RingSPSC T is the type of messages being processed