queue

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 2 Imported by: 0 modules, 0 packages

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Queue

type Queue[T any] struct {
	// contains filtered or unexported fields
}

Queue 封装了 UMPSCQueue 和计数器

func New

func New[T any]() *Queue[T]

New 创建一个新的 Queue 实例

func (*Queue[T]) Dequeue

func (q *Queue[T]) Dequeue() T

Dequeue 从队列中获取数据并更新计数器 (仅单消费者!!!)

func (*Queue[T]) Enqueue

func (q *Queue[T]) Enqueue(value T)

Enqueue 向队列中添加数据并更新计数器 (多生产者: 安全)

func (*Queue[T]) EnqueueCount added in v1.3.12

func (q *Queue[T]) EnqueueCount() uint64

EnqueueCount 返回此队列实例创建以来的累计 Enqueue 调用数, 出队不会扣减. 只读取既有分片计数器, 不清零计数, 不推进 RateState 的速率采样窗口. 并发读写安全, 但不提供各分片同一时刻的原子快照; 计数在实际发布元素前递增, 因此不能用它判断当前可出队数量或消费完成量. 读取成本与分片数成正比.

func (*Queue[T]) Len

func (q *Queue[T]) Len() uint64

Len 返回当前队列长度

func (*Queue[T]) RateState

func (q *Queue[T]) RateState() (rate float64, enqueueCount, lastEnqueueCount uint64)

RateState 返回入队速率, 当前计数, 上一次计数

Jump to

Keyboard shortcuts

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