delayqueue

package
v0.0.0-...-4891ed2 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2025 License: MIT Imports: 3 Imported by: 0

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