timer

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Forever   = -1 //  无限循环
	Once      = 1  // 一次
	Instantly = 0  // 立刻
)
View Source
const (
	NoMark = "" // 没有设置标记的定时器
)

Variables

This section is empty.

Functions

func OnOffsetTimeNewDayEvent added in v0.0.28

func OnOffsetTimeNewDayEvent(name string)

OnOffsetTimeNewDayEvent 偏移时间新的一天事件

func OnSystemNewDayEvent added in v0.0.28

func OnSystemNewDayEvent(name string)

OnSystemNewDayEvent 系统新的一天事件

func RegOffsetTimeNewDayEvent added in v0.0.28

func RegOffsetTimeNewDayEvent(ticker *Ticker, name string, offset *offset.Time, trigger bool, handle OffsetTimeNewDayEventHandle)

RegOffsetTimeNewDayEvent 注册偏移时间新的一天事件

  • 建议全局注册一个事件后再另行拓展
  • 与 RegSystemNewDayEvent 类似,但是触发时间为 offset 时间到达每天的 00:00:00

func RegSystemNewDayEvent added in v0.0.28

func RegSystemNewDayEvent(ticker *Ticker, name string, trigger bool, handle SystemNewDayEventHandle)

RegSystemNewDayEvent 注册系统新的一天事件

  • 建议全局注册一个事件后再另行拓展
  • 将特定 name 的定时任务注册到 ticker 中,在系统时间到达每天的 00:00:00 时触发,如果 trigger 为 true,则立即触发一次

Types

type OffsetTimeNewDayEventHandle added in v0.0.28

type OffsetTimeNewDayEventHandle func()

type Option

type Option func(ticker *Ticker)

func WithCaller

func WithCaller(handle func(name string, caller func())) Option

WithCaller 通过其他的 handle 执行 Caller

func WithMark added in v0.0.3

func WithMark(mark string) Option

WithMark 通过特定的标记创建定时器

type Scheduler

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

Scheduler 调度器

func (*Scheduler) Caller

func (slf *Scheduler) Caller()

Caller 可由外部发起调用的执行函数

func (*Scheduler) Name

func (slf *Scheduler) Name() string

Name 获取调度器名称

func (*Scheduler) Next

func (slf *Scheduler) Next(prev time.Time) time.Time

Next 获取下一次执行的时间

type SystemNewDayEventHandle added in v0.0.28

type SystemNewDayEventHandle func()

type Ticker

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

Ticker 定时器

func GetTicker

func GetTicker(size int, options ...Option) *Ticker

func (*Ticker) After

func (slf *Ticker) After(name string, after time.Duration, handleFunc interface{}, args ...interface{})

After 设置一个在特定时间后运行一次的调度器

func (*Ticker) GetSchedulers

func (slf *Ticker) GetSchedulers() []string

GetSchedulers 获取所有调度器名称

func (*Ticker) IsStopped

func (slf *Ticker) IsStopped(name string) bool

IsStopped 特定名称的调度器是否已停止

func (*Ticker) Loop

func (slf *Ticker) Loop(name string, after, interval time.Duration, times int, handleFunc interface{}, args ...interface{})

Loop 设置一个在特定时间后反复运行的调度器

func (*Ticker) Mark added in v0.0.3

func (slf *Ticker) Mark() string

Mark 获取定时器的标记

  • 通常用于鉴别定时器来源

func (*Ticker) Release

func (slf *Ticker) Release()

Release 释放定时器,并将定时器重新放回 Timer 池中

func (*Ticker) StopTimer

func (slf *Ticker) StopTimer(name string)

StopTimer 停止特定名称的调度器

type Timer

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

func (*Timer) NewTicker

func (slf *Timer) NewTicker(size int, options ...Option) *Ticker

Jump to

Keyboard shortcuts

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