timer

package
v0.0.0-...-37d5b15 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Next

type Next interface {
	Next(time.Time) time.Time
}

type Option

type Option func(c *option)

func WithMinHeap

func WithMinHeap() Option

func WithRbtree

func WithRbtree() Option

TODO

func WithSkipList

func WithSkipList() Option

TODO

func WithTimeWheel

func WithTimeWheel() Option

type Time

type Time struct {
	sync.Mutex
	// contains filtered or unexported fields
}

先使用sync.Mutex实现功能 后面使用cas优化

func (*Time) Stop

func (t *Time) Stop()

一个timeNode节点有4个状态 1.存在于初始化链表中 2.被移动到tmp链表 3.1 和 3.2是if else的状态

3.1被移动到new链表
3.2直接执行

1和3.1状态是没有问题的 2和3.2状态会是没有锁保护下的操作,会有数据竞争

type TimeNoder

type TimeNoder interface {
	Stop()
}

停止单个定时器

type Timer

type Timer interface {
	// 一次性定时器
	AfterFunc(expire time.Duration, callback func()) TimeNoder

	// 周期性定时器
	ScheduleFunc(expire time.Duration, callback func()) TimeNoder

	// 自定义下次的时间
	CustomFunc(n Next, callback func()) TimeNoder

	// 运行
	Run()

	// 停止所有定时器
	Stop()
}

定时器接口

func NewTimer

func NewTimer(opt ...Option) Timer

定时器构造函数

type Timerv2

type Timerv2 interface {
	// 一次性定时器
	//TimerStart(expire time.Duration, m interface{}, callback func(t TimeNoder, v interface{})) TimeNoder
	// 周期性定时器
	TimerLoopInit(expire time.Duration, m interface{}, callback func(t TimeNoder, v interface{})) TimeNoder

	// 运行
	TimerStart()
}

定时器接口 version 2

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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