timer

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Forever   = -1 //  无限循环
	Once      = 1  // 一次
	Instantly = 0  // 立刻
)
View Source
const (
	DefaultTickerPoolSize = 96
)
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,则立即触发一次

func SetPoolSize added in v0.3.6

func SetPoolSize(size int)

SetPoolSize 设置标准池定时器池大小

  • 默认值为 DefaultTickerPoolSize,当定时器池中的定时器不足时,会自动创建新的定时器,当定时器释放时,会将多余的定时器进行释放,否则将放入定时器池中

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 Pool added in v0.3.6

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

Pool 定时器池

func NewPool added in v0.3.6

func NewPool(tickerPoolSize int) *Pool

NewPool 创建一个定时器池,当 tickerPoolSize 小于等于 0 时,将会引发 panic,可指定为 DefaultTickerPoolSize

func (*Pool) ChangePoolSize added in v0.3.6

func (slf *Pool) ChangePoolSize(size int) error

ChangePoolSize 改变定时器池大小

  • 当传入的大小小于或等于 0 时,将会返回错误,并且不会发生任何改变

func (*Pool) GetTicker added in v0.3.6

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

GetTicker 获取一个新的定时器

func (*Pool) Release added in v0.3.6

func (slf *Pool) Release()

Release 释放定时器池的资源,释放后由其产生的 Ticker 在 Ticker.Release 后将不再回到池中,而是直接释放

  • 虽然定时器池已被释放,但是依旧可以产出 Ticker

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

GetTicker 获取标准池中的一个定时器

func (*Ticker) After

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

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

func (*Ticker) Cron added in v0.3.3

func (slf *Ticker) Cron(name, expression string, handleFunc interface{}, args ...interface{})

Cron 通过 cron 表达式设置一个调度器,当 cron 表达式错误时,将会引发 panic

func (*Ticker) CronByInstantly added in v0.3.6

func (slf *Ticker) CronByInstantly(name, expression string, handleFunc interface{}, args ...interface{})

CronByInstantly 与 Cron 相同,但是会立即执行一次

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 释放定时器,并将定时器重新放回 Pool 池中

func (*Ticker) StopTimer

func (slf *Ticker) StopTimer(name string)

StopTimer 停止特定名称的调度器

Jump to

Keyboard shortcuts

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