timer

package
v0.0.20 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2023 License: MIT Imports: 4 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

This section is empty.

Types

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 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) *Ticker

Jump to

Keyboard shortcuts

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