concurrent

package module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 28, 2026 License: BSD-3-Clause Imports: 4 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 Job

type Job func() error

Job represents a unit of work to be processed by the worker pool

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址