timewheel

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2023 License: MIT Imports: 7 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 struct {
	C chan interface{} // 利用channel来传输任务
	// contains filtered or unexported fields
}

DelayQueue 延时队列

func NewDelayQueue

func NewDelayQueue(size int) *DelayQueue

func (*DelayQueue) Channel

func (queue *DelayQueue) Channel() chan interface{}

Channel 返回

func (*DelayQueue) Offer

func (queue *DelayQueue) Offer(val interface{}, expiration int64)

Offer 往队列里加入一个任务

func (*DelayQueue) Poll

func (queue *DelayQueue) Poll(exitC chan struct{}, nowF func() int64)

Poll 拉取任务

type Item

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

type TimeWheel

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

TimeWheel 实现一个时间轮定时器,在指定时间运行指定的任务

func New

func New(tick time.Duration, wheelSize int64) *TimeWheel

New 实例化一个时间轮定时器

func (*TimeWheel) AfterFunc

func (tw *TimeWheel) AfterFunc(d time.Duration, f func()) *Timer

AfterFunc

func (*TimeWheel) Start

func (tw *TimeWheel) Start()

func (*TimeWheel) Stop

func (tw *TimeWheel) Stop()

Stop 关闭

type Timer

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

func (*Timer) Reset

func (t *Timer) Reset(d time.Duration) bool

Reset 将定时任务往后延时执行

func (*Timer) Stop

func (t *Timer) Stop() (stopped bool)

Stop 停止任务,当任务已执行时返回false

Jump to

Keyboard shortcuts

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