Documentation
¶
Overview ¶
Package concurrent provides concurrency control utilities.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConcurrencyLimiter ¶
type ConcurrencyLimiter struct {
// contains filtered or unexported fields
}
ConcurrencyLimiter provides token-based concurrency limiting.
func NewConcurrencyLimiter ¶
func NewConcurrencyLimiter(maxConcurrency int, name string, reg metric.Registry) *ConcurrencyLimiter
NewConcurrencyLimiter creates a new concurrency limiter with specified max concurrent operations
func (*ConcurrencyLimiter) Acquire ¶
func (cl *ConcurrencyLimiter) Acquire(ctx context.Context) error
Acquire acquires a concurrency token, blocking until one is available
func (*ConcurrencyLimiter) Active ¶
func (cl *ConcurrencyLimiter) Active() int
Active returns the number of currently active operations
func (*ConcurrencyLimiter) Available ¶
func (cl *ConcurrencyLimiter) Available() int
Available returns the number of available concurrency slots
func (*ConcurrencyLimiter) Capacity ¶
func (cl *ConcurrencyLimiter) Capacity() int
Capacity returns the total capacity of the limiter
func (*ConcurrencyLimiter) Release ¶
func (cl *ConcurrencyLimiter) Release()
Release releases a concurrency token
func (*ConcurrencyLimiter) TryAcquire ¶
func (cl *ConcurrencyLimiter) TryAcquire() bool
TryAcquire tries to acquire a concurrency token without blocking
type WorkerPool ¶
type WorkerPool struct {
// contains filtered or unexported fields
}
WorkerPool manages a pool of workers for processing tasks
func NewWorkerPool ¶
func NewWorkerPool(ctx context.Context, workers int, maxQueueSize int, name string, reg metric.Registry) *WorkerPool
NewWorkerPool creates a new worker pool with specified number of workers
func (*WorkerPool) QueueCapacity ¶
func (wp *WorkerPool) QueueCapacity() int
QueueCapacity returns the maximum number of queued jobs
func (*WorkerPool) QueueSize ¶
func (wp *WorkerPool) QueueSize() int
QueueSize returns the current number of queued jobs
func (*WorkerPool) Running ¶
func (wp *WorkerPool) Running() bool
Running returns whether the worker pool is still running
func (*WorkerPool) Stop ¶
func (wp *WorkerPool) Stop()
Stop stops the worker pool and waits for all workers to finish
func (*WorkerPool) Submit ¶
func (wp *WorkerPool) Submit(job Job) error
Submit submits a job to the worker pool
func (*WorkerPool) SubmitAndWait ¶
func (wp *WorkerPool) SubmitAndWait(job Job) error
SubmitAndWait submits a job and waits for it to complete