delayqueue

package
v0.0.0-...-0c1b9ed Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 3 Imported by: 1 module, 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 DelayQueue

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

DelayQueue 基于小顶堆的延迟队列,单 timer + 唤醒通道,由 loop 协程独占管理 timer。

func New

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

New 创建并启动延迟队列

func (*DelayQueue[T]) Close

func (dq *DelayQueue[T]) Close()

Close 关闭队列(只发退出信号,不直接操作 timer)

func (*DelayQueue[T]) Len

func (dq *DelayQueue[T]) Len() int

Len 获取队列长度(近似,未计入已到期但未发送的瞬时)

func (*DelayQueue[T]) PopChan

func (dq *DelayQueue[T]) PopChan() <-chan Item[T]

PopChan 获取到期任务通道

func (*DelayQueue[T]) Push

func (dq *DelayQueue[T]) Push(v T, at time.Time)

Push 添加延迟任务(若更早,唤醒 loop 以重置 timer)

type Item

type Item[T any] struct {
	At    time.Time
	Value T
	// contains filtered or unexported fields
}

Item 延迟任务项

Jump to

Keyboard shortcuts

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