ttime

package
v0.0.0-...-8639602 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2022 License: BSL-1.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(layout, value string) (time.Time, error)

Parse 避免time.local 忘记,因为标准库 少了时区,会导致解析时间少了 8小时

Types

type JobFunc

type JobFunc func(kv ...interface{})

JobFunc 延时任务回调函数

type Option

type Option func(tw *TimeWheel)

func WithInterval

func WithInterval(interval time.Duration) Option

func WithSlotNum

func WithSlotNum(slotNum int) Option

WithSlotNum 设置槽的数量

type Task

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

Task 延时任务

type TimeWheel

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

TimeWheel 时间轮

func NewTimeWheel

func NewTimeWheel(opts ...Option) *TimeWheel

NewTimeWheel New 创建时间轮 初始化时间轮 interval 第一个参数为tick刻度, 即时间轮多久转动一次 slotNum 第二个参数为时间轮槽slot数量 interval 精确到秒 , 精度越高越耗性能 ,建议到秒级别 使用步骤 1、newtimewheel 2、start 3、addtimer 4 stop

func (*TimeWheel) AddTimer

func (tw *TimeWheel) AddTimer(delay time.Duration, key interface{}, callBack JobFunc, args ...interface{})

AddTimer 添加定时器 key为定时器唯一标识

func (*TimeWheel) RemoveTimer

func (tw *TimeWheel) RemoveTimer(key interface{})

RemoveTimer 删除定时器 key为添加定时器时传递的定时器唯一标识

func (*TimeWheel) Start

func (tw *TimeWheel) Start()

Start 启动时间轮

func (*TimeWheel) Stop

func (tw *TimeWheel) Stop()

Stop 停止时间轮

Jump to

Keyboard shortcuts

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