Documentation
¶
Index ¶
- Constants
- func AddWellKnownMetaProperties(props ...string)
- func GetWellKnownMetaProperties() []string
- func HasWellKnownMetaProperty(prop string) bool
- func RemoveWellKnownMetaProperties(props ...string)
- type Disruptor
- type DynamicStack
- func (s *DynamicStack[T]) IsEmpty() bool
- func (s *DynamicStack[T]) Peek() (T, bool)
- func (s *DynamicStack[T]) Pop() (T, bool)
- func (s *DynamicStack[T]) PopBatch(n int64) ([]T, bool)
- func (s *DynamicStack[T]) Push(v T) bool
- func (s *DynamicStack[T]) PushBatch(v ...T) bool
- func (s *DynamicStack[T]) Size() int64
- func (s *DynamicStack[T]) ToSlice() []T
- type Meta
- type Stack
- type StaticStack
- func (s *StaticStack[T]) Capacity() int64
- func (s *StaticStack[T]) IsEmpty() bool
- func (s *StaticStack[T]) IsFull() bool
- func (s *StaticStack[T]) Peek() (T, bool)
- func (s *StaticStack[T]) Pop() (T, bool)
- func (s *StaticStack[T]) PopBatch(n int64) ([]T, bool)
- func (s *StaticStack[T]) Push(v T) bool
- func (s *StaticStack[T]) PushBatch(v ...T) bool
- func (s *StaticStack[T]) Size() int64
- func (s *StaticStack[T]) ToSlice() []T
- type SyncQueue
- func (q *SyncQueue[T]) Peek() (T, bool)
- func (q *SyncQueue[T]) Pop() (T, bool)
- func (q *SyncQueue[T]) PopN(n int) ([]T, bool)
- func (q *SyncQueue[T]) Preserve()
- func (q *SyncQueue[T]) PreserveAndPop() (T, bool)
- func (q *SyncQueue[T]) Push(v T) error
- func (q *SyncQueue[T]) RollBack()
- func (q *SyncQueue[T]) Size() int
- func (q *SyncQueue[T]) Unwrap() []T
- func (q *SyncQueue[T]) UnwrapAndFlush() []T
- func (q *SyncQueue[T]) WaitTillEmpty(timeout time.Duration) error
- func (q *SyncQueue[T]) WaitTillNotEmpty(timeout time.Duration) error
- type SyncStack
- func (s *SyncStack[T, S]) IsEmpty() bool
- func (s *SyncStack[T, S]) Peek() (T, bool)
- func (s *SyncStack[T, S]) Pop() (T, bool)
- func (s *SyncStack[T, S]) PopBatch(n int64) ([]T, bool)
- func (s *SyncStack[T, S]) Push(v T) bool
- func (s *SyncStack[T, S]) PushBatch(v ...T) bool
- func (s *SyncStack[T, S]) Size() int64
- func (s *SyncStack[T, S]) ToSlice() []T
- type Task
- type WorkerPool
- type WorkerPoolOptions
Constants ¶
const ( // DefaultBufferSize is the default buffer size (64K entries) DefaultBufferSize = 1 << 16 // MinBufferSize is the minimum buffer size (64 entries) MinBufferSize = 1 << 6 )
Variables ¶
This section is empty.
Functions ¶
func AddWellKnownMetaProperties ¶
func AddWellKnownMetaProperties(props ...string)
Adds new well-known meta properties, but only if they don't already exist.
func GetWellKnownMetaProperties ¶
func GetWellKnownMetaProperties() []string
Returns a copy of a slice with all well-known meta properties.
func HasWellKnownMetaProperty ¶
Reports if the specified property exists in well-known meta properties.
func RemoveWellKnownMetaProperties ¶
func RemoveWellKnownMetaProperties(props ...string)
Removes specified well-known meta properties.
Types ¶
type Disruptor ¶
type Disruptor[T any] struct { // contains filtered or unexported fields }
Implements the LMAX Disruptor pattern for high-performance ring buffer messaging.
func NewDisruptor ¶
creates a new Disruptor with default buffer size (64K)
func NewDisruptorWithSize ¶
Creates a new Disruptor with specified buffer size. Buffer size must be a power of 2 and at least MinBufferSize.
func (*Disruptor[T]) Close ¶
func (d *Disruptor[T]) Close()
Closes the Disruptor and signals all goroutines to stop. After closing, the disruptor cannot be used again.
func (*Disruptor[T]) Consume ¶
Starts consuming entries from the disruptor using the provided handler. This method blocks until the disruptor is closed. Returns error if disruptor is already closed.
type DynamicStack ¶ added in v1.2.0
type DynamicStack[T any] struct { // contains filtered or unexported fields }
Last-In-First-Out dynamic stack data structure.
func NewDynamicStack ¶ added in v1.2.0
func NewDynamicStack[T any](capacity int) *DynamicStack[T]
Sets capacity to default if it's <= 0.
func (*DynamicStack[T]) IsEmpty ¶ added in v1.2.0
func (s *DynamicStack[T]) IsEmpty() bool
func (*DynamicStack[T]) Peek ¶ added in v1.2.0
func (s *DynamicStack[T]) Peek() (T, bool)
Gets top element from the stack. Returns false if stack is empty.
func (*DynamicStack[T]) Pop ¶ added in v1.2.0
func (s *DynamicStack[T]) Pop() (T, bool)
Removes top element from the stack. Returns false if stack is empty.
func (*DynamicStack[T]) PopBatch ¶ added in v1.2.0
func (s *DynamicStack[T]) PopBatch(n int64) ([]T, bool)
Removes n top elements from the stack. Returns false if stack is empty.
func (*DynamicStack[T]) Push ¶ added in v1.2.0
func (s *DynamicStack[T]) Push(v T) bool
Pushes new element on top of the stack. Always returns true.
func (*DynamicStack[T]) PushBatch ¶ added in v1.2.0
func (s *DynamicStack[T]) PushBatch(v ...T) bool
Pushes new elements on top of the stack. Always returns true.
func (*DynamicStack[T]) Size ¶ added in v1.2.0
func (s *DynamicStack[T]) Size() int64
Returns amount of elements in the stack.
func (*DynamicStack[T]) ToSlice ¶ added in v1.2.0
func (s *DynamicStack[T]) ToSlice() []T
type Stack ¶ added in v1.2.0
type Stack[T any] interface { // Pushes new element on top of the stack. // Returns false if stack is overflowed (only if it can be overflowed). Push(v T) bool // Pushes new elements on top of the stack. // Returns false if stack is overflowed (only if it can be overflowed). PushBatch(v ...T) bool // Removes top element from the stack. // Returns false if stack is empty. Pop() (T, bool) // Removes n top elements from the stack. // Returns false if stack is empty. PopBatch(n int64) ([]T, bool) // Gets top element from the stack. // Returns false if stack is empty. Peek() (T, bool) // Returns amount of elements in the stack. Size() int64 IsEmpty() bool ToSlice() []T }
Represents Last-In-First-Out stack.
type StaticStack ¶ added in v1.2.0
type StaticStack[T any] struct { // contains filtered or unexported fields }
Last-In-First-Out static stack data structure.
func NewStaticStack ¶ added in v1.2.0
func NewStaticStack[T any](capacity int64) *StaticStack[T]
Panics if capacity is <= 0.
func (*StaticStack[T]) Capacity ¶ added in v1.2.0
func (s *StaticStack[T]) Capacity() int64
Returns max stack size.
func (*StaticStack[T]) IsEmpty ¶ added in v1.2.0
func (s *StaticStack[T]) IsEmpty() bool
func (*StaticStack[T]) IsFull ¶ added in v1.2.0
func (s *StaticStack[T]) IsFull() bool
func (*StaticStack[T]) Peek ¶ added in v1.2.0
func (s *StaticStack[T]) Peek() (T, bool)
Gets top element from the stack. Returns false if stack is empty.
func (*StaticStack[T]) Pop ¶ added in v1.2.0
func (s *StaticStack[T]) Pop() (T, bool)
Removes top element from the stack. Returns false if stack is empty.
func (*StaticStack[T]) PopBatch ¶ added in v1.2.0
func (s *StaticStack[T]) PopBatch(n int64) ([]T, bool)
Removes n top elements from the stack. Returns false if stack is empty.
func (*StaticStack[T]) Push ¶ added in v1.2.0
func (s *StaticStack[T]) Push(v T) bool
Pushes new element on top of the stack. Returns false if stack is overflowed.
func (*StaticStack[T]) PushBatch ¶ added in v1.2.0
func (s *StaticStack[T]) PushBatch(v ...T) bool
Pushes new elements on top of the stack. Returns false if stack is overflowed (only if it can be overflowed).
func (*StaticStack[T]) Size ¶ added in v1.2.0
func (s *StaticStack[T]) Size() int64
Returns amount of elements in the stack.
func (*StaticStack[T]) ToSlice ¶ added in v1.2.0
func (s *StaticStack[T]) ToSlice() []T
type SyncQueue ¶
type SyncQueue[T comparable] struct { // contains filtered or unexported fields }
Concurrency-safe first-in-first-out (FIFO) queue.
func NewSyncQueue ¶
func NewSyncQueue[T comparable](sizeLimit int) *SyncQueue[T]
Creates a new thread-safe queue with optional size limit. To disable size limit, set sizeLimit <= 0.
func (*SyncQueue[T]) Peek ¶
Returns the first element of the queue without removing it. If queue isn't empty - returns first element and true. If queue is empty - returns zero-value of T and false.
func (*SyncQueue[T]) Pop ¶
Removes and returns the first element of the queue. Same as Peek(), but also deletes first element in queue.
func (*SyncQueue[T]) PopN ¶
Removes and returns up to n elements from the queue. If n is greater than queue size, n will be adjusted to the queue size to prevent panic. If queue is empty - returns nil and false.
func (*SyncQueue[T]) Preserve ¶
func (q *SyncQueue[T]) Preserve()
Saves the head element of the queue for potential rollback.
func (*SyncQueue[T]) PreserveAndPop ¶
Preserves the current head element and then pops it from the queue. This is equivalent to calling Preserve() followed by Pop().
func (*SyncQueue[T]) RollBack ¶
func (q *SyncQueue[T]) RollBack()
Restores the previously preserved element to the front of the queue. Does nothing if no element was preserved.
func (*SyncQueue[T]) Unwrap ¶
func (q *SyncQueue[T]) Unwrap() []T
Returns a copy of the internal slice containing all current queue elements.
func (*SyncQueue[T]) UnwrapAndFlush ¶
func (q *SyncQueue[T]) UnwrapAndFlush() []T
Returns a copy of all current queue elements and removes them from the queue. Same as Unwrap, but also deletes all elements in queue.
func (*SyncQueue[T]) WaitTillEmpty ¶
Blocks until the queue becomes empty. To disable timeout, set it to <= 0. Returns errs.StatusTimeout if timeout exceeded, nil otherwise.
type SyncStack ¶ added in v1.2.0
Wrapper that makes S thread-Safe. It just wraps Stack methods of S using mutex, so it's not a some kind of stack on it's own. (although it inherently implements Stack interface)
func NewSyncStack ¶ added in v1.2.0
func (*SyncStack[T, S]) Peek ¶ added in v1.2.0
Gets top element from S. Returns false if stack is empty.
func (*SyncStack[T, S]) Pop ¶ added in v1.2.0
Removes top element from S. Returns false if stack is empty.
func (*SyncStack[T, S]) PopBatch ¶ added in v1.2.0
Removes n top elements from the stack. Returns false if stack is empty.
func (*SyncStack[T, S]) Push ¶ added in v1.2.0
Pushes new element on top of S. Returns false if S is overflowed (only if it can be overflowed).
func (*SyncStack[T, S]) PushBatch ¶ added in v1.2.0
Pushes new elements on top of the stack. Returns false if stack is overflowed (only if it can be overflowed).
type Task ¶
type Task interface {
// Executes the task's logic.
Process()
}
Represents an executable task that can be processed by a worker pool.
type WorkerPool ¶
type WorkerPool struct {
// contains filtered or unexported fields
}
Manages a pool of goroutine workers that process tasks concurrently.
func NewWorkerPool ¶
func NewWorkerPool(ctx context.Context, opt *WorkerPoolOptions) *WorkerPool
Creates a new worker pool with the given parent context and options. If opt is nil, it will be created using default values of WorkerPoolOptions fields.
func (*WorkerPool) Cancel ¶
func (wp *WorkerPool) Cancel() error
Gracefully shuts down the worker pool. The worker pool will finish all its tasks before stopping. Once canceled, the worker pool cannot be started again.
func (*WorkerPool) IsCanceled ¶
func (wp *WorkerPool) IsCanceled() bool
Returns true if the worker pool has been canceled.
func (*WorkerPool) Push ¶
func (wp *WorkerPool) Push(t Task) error
Adds a new task to the worker pool queue. Returns error if worker pool is canceled.
func (*WorkerPool) Start ¶
func (wp *WorkerPool) Start(workerCount int)
Starts the worker pool with the specified number of worker goroutines. This method is idempotent - subsequent calls will have no effect.
type WorkerPoolOptions ¶
type WorkerPoolOptions struct {
// Default: 1. If <= 0, will be set to default.
BatchSize int
// Maximum time to wait for tasks to complete on shutdown.
// Default: 1s. If <= 0, will be set to default.
StopTimeout time.Duration
}
Holds configuration options for a worker pool.