timingwheel

package
v0.0.0-...-8c343c0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SingleTimeWheel

type SingleTimeWheel struct {
	// contains filtered or unexported fields
}

SingleTimeWheel 定义单级时间轮的数据结构

func NewSingleTimeWheel

func NewSingleTimeWheel(tickDuration time.Duration, slotNumber int) *SingleTimeWheel

NewSingleTimeWheel 新建一个单级时间轮

func (*SingleTimeWheel) AddTask

func (own *SingleTimeWheel) AddTask(delay time.Time, job func(), period time.Duration, repeats ...int) int64

AddTask 添加定时性任务

  • delay:执行首轮任务的延迟时间
  • job:任务函数
  • period:任务重复执行的时间间隔
  • repeats:重复执行任务的次数(repeats=-1 表示一直循环执行定时任务)
  • 注意:重复执行任务的间隔时间 period 需要大于时间轮的最小嘀嗒时间;

func (*SingleTimeWheel) CancelTask

func (own *SingleTimeWheel) CancelTask(tid int64, done func()) bool

CancelTask 取消任务

  • tid:任务ID
  • done:任何取消时的回调函数

func (*SingleTimeWheel) Start

func (own *SingleTimeWheel) Start()

Start 启动时间轮

func (*SingleTimeWheel) Stop

func (own *SingleTimeWheel) Stop()

Stop 停止时间轮

type Task

type Task struct {
	// contains filtered or unexported fields
}

Task 定义定时任务的数据结构

Jump to

Keyboard shortcuts

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