Documentation ¶
Overview ¶
Package mb - queue with message batching feature
Index ¶
- Variables
- type MB
- func (mb *MB[T]) Add(msgs ...T) (err error)
- func (mb *MB[T]) Close() (err error)
- func (mb *MB[T]) GetAll() (msgs []T)
- func (mb *MB[T]) Len() (l int)
- func (mb *MB[T]) Pause()
- func (mb *MB[T]) Resume()
- func (mb *MB[T]) Stats() (addCount, addMsgsCount, getCount, getMsgsCount int64)
- func (mb *MB[T]) TryAdd(msgs ...T) (err error)
- func (mb *MB[T]) Wait() (msgs []T)
- func (mb *MB[T]) WaitMax(max int) (msgs []T)
- func (mb *MB[T]) WaitMin(min int) (msgs []T)
- func (mb *MB[T]) WaitMinMax(min, max int) (msgs []T)
Constants ¶
This section is empty.
Variables ¶
var ErrClosed = errors.New("mb: MB closed")
ErrClosed is returned when you add message to closed queue
var ErrOverflowed = errors.New("mb: overflowed")
ErrOverflowed means new messages can't be added until there is free space in the queue
var ErrTooManyMessages = errors.New("mb: too many messages")
ErrTooManyMessages means that adding more messages (at one call) than the limit
Functions ¶
This section is empty.
Types ¶
type MB ¶
type MB[T any] struct { // contains filtered or unexported fields }
MB - message batching object Implements queue. Based on condition variables
func (*MB[T]) Add ¶
Add - adds new messages to queue. When queue is closed - returning ErrClosed When count messages bigger then queue size - returning ErrTooManyMessages When the queue is full - wait until will free place
func (*MB[T]) Close ¶
Close closes the queue All added messages will be available for Wait When queue paused messages do not be released for Wait (use GetAll for fetching them)
func (*MB[T]) GetAll ¶
func (mb *MB[T]) GetAll() (msgs []T)
GetAll return all messages and flush queue Works on closed queue
func (*MB[T]) Stats ¶
Stats returning current statistic of queue usage addCount - count of calls Add addMsgsCount - count of added messages getCount - count of calls Wait getMsgsCount - count of issued messages
func (*MB[T]) TryAdd ¶
TryAdd - adds new messages to queue. When queue is closed - returning ErrClosed When count messages bigger then queue size - returning ErrTooManyMessages When the queue is full - returning ErrOverflowed
func (*MB[T]) Wait ¶
func (mb *MB[T]) Wait() (msgs []T)
Wait until anybody add message Returning array of accumulated messages When queue will be closed length of array will be 0
func (*MB[T]) WaitMinMax ¶
WaitMinMax it's Wait with limit of minimum and maximum returning array size value < 0 means no limit