xtimer

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	STATUS_READY   = 0
	STATUS_RUNNING = 1
	STATUS_STOPPED = 2
	STATUS_CLOSED  = -1
)

Variables

This section is empty.

Functions

func DelayAdd

func DelayAdd(delay time.Duration, interval time.Duration, job JobFunc)

延迟添加循环任务。

func DelayAddEntry

func DelayAddEntry(delay time.Duration, interval time.Duration, job JobFunc, singleton bool, times int, status int)

延迟添加循环任务, 支持完整的参数。

func DelayAddOnce

func DelayAddOnce(delay time.Duration, interval time.Duration, job JobFunc)

延迟添加只运行一次的循环任务,delay参数单位为秒

func DelayAddSingleton

func DelayAddSingleton(delay time.Duration, interval time.Duration, job JobFunc)

延迟添加单例循环任务,delay参数单位为秒

func DelayAddTimes

func DelayAddTimes(delay time.Duration, interval time.Duration, times int, job JobFunc)

延迟添加运行指定次数的循环任务,delay参数单位为秒

func Exit

func Exit()

在Job方法中调用,停止并删除当前运行的任务。

func SetInterval

func SetInterval(interval time.Duration, job JobFunc)

类似与js中的SetInterval,每隔一段时间执行指定回调函数。

func SetTimeout

func SetTimeout(delay time.Duration, job JobFunc)

类似与js中的SetTimeout,一段时间后执行回调函数。

Types

type JobFunc

type JobFunc = func()

任务执行方法

type TEntry

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

循环任务项

func Add

func Add(interval time.Duration, job JobFunc) *TEntry

添加执行方法。

func AddEntry

func AddEntry(interval time.Duration, job JobFunc, singleton bool, times int, status int) *TEntry

添加执行方法,更多参数控制。

func AddOnce

func AddOnce(interval time.Duration, job JobFunc) *TEntry

添加只运行一次的循环任务。

func AddSingleton

func AddSingleton(interval time.Duration, job JobFunc) *TEntry

添加单例运行循环任务。

func AddTimes

func AddTimes(interval time.Duration, times int, job JobFunc) *TEntry

添加运行指定次数的循环任务。

func (*TEntry) Close

func (entry *TEntry) Close()

关闭当前任务

func (*TEntry) IsSingleton

func (entry *TEntry) IsSingleton() bool

是否单例运行

func (*TEntry) Run

func (entry *TEntry) Run()

执行任务

func (*TEntry) SetSingleton

func (entry *TEntry) SetSingleton(enabled bool)

设置单例运行

func (*TEntry) SetStatus

func (entry *TEntry) SetStatus(status int) int

设置任务状态

func (*TEntry) SetTimes

func (entry *TEntry) SetTimes(times int)

设置任务的运行次数

func (*TEntry) Start

func (entry *TEntry) Start()

启动当前任务

func (*TEntry) Status

func (entry *TEntry) Status() int

获取任务状态

func (*TEntry) Stop

func (entry *TEntry) Stop()

停止当前任务

type TTimer

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

定时器/分层时间轮

func New

func New(slot int, interval time.Duration, level ...int) *TTimer

创建分层时间轮

func (*TTimer) Add

func (t *TTimer) Add(interval time.Duration, job JobFunc) *TEntry

添加循环任务

func (*TTimer) AddEntry

func (t *TTimer) AddEntry(interval time.Duration, job JobFunc, singleton bool, times int, status int) *TEntry

添加定时任务

func (*TTimer) AddOnce

func (t *TTimer) AddOnce(interval time.Duration, job JobFunc) *TEntry

添加只运行一次的循环任务

func (*TTimer) AddSingleton

func (t *TTimer) AddSingleton(interval time.Duration, job JobFunc) *TEntry

添加单例运行循环任务

func (*TTimer) AddTimes

func (t *TTimer) AddTimes(interval time.Duration, times int, job JobFunc) *TEntry

添加运行指定次数的循环任务。

func (*TTimer) Close

func (t *TTimer) Close()

关闭定时器

func (*TTimer) DelayAdd

func (t *TTimer) DelayAdd(delay time.Duration, interval time.Duration, job JobFunc)

延迟添加循环任务。

func (*TTimer) DelayAddEntry

func (t *TTimer) DelayAddEntry(delay time.Duration, interval time.Duration, job JobFunc, singleton bool, times int, status int)

延迟添加循环任务, 支持完整的参数。

func (*TTimer) DelayAddOnce

func (t *TTimer) DelayAddOnce(delay time.Duration, interval time.Duration, job JobFunc)

延迟添加只运行一次的循环任务

func (*TTimer) DelayAddSingleton

func (t *TTimer) DelayAddSingleton(delay time.Duration, interval time.Duration, job JobFunc)

延迟添加单例循环任务

func (*TTimer) DelayAddTimes

func (t *TTimer) DelayAddTimes(delay time.Duration, interval time.Duration, times int, job JobFunc)

延迟添加只运行一次的循环任务

func (*TTimer) Start

func (t *TTimer) Start()

启动定时器

func (*TTimer) Stop

func (t *TTimer) Stop()

定制定时器

Jump to

Keyboard shortcuts

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