timer

package
v0.0.0-...-2692626 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package timer 定时器 优先级:加入顺序,到期

Index

Constants

View Source
const (
	ScanSecondDurationDefault      = time.Millisecond * 100
	ScanMillisecondDurationDefault = time.Millisecond * 25
)

Variables

This section is empty.

Functions

func DelMillisecond

func DelMillisecond(t *Millisecond)

DelMillisecond 删除毫秒级定时器

NOTE 必须与该timerOutChan线性处理.如:在同一个goroutine select中处理数据
参数:
	毫秒定时器

func DelSecond

func DelSecond(t *Second)

DelSecond 删除秒级定时器 同 DelMillisecond

Types

type Mgr

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

Mgr 定时器管理器

func GetInstance

func GetInstance() *Mgr

GetInstance 获取

func (*Mgr) AddMillisecond

func (p *Mgr) AddMillisecond(cb OnFun, arg interface{}, expireMillisecond int64) *Millisecond

AddMillisecond 添加毫秒级定时器

参数:
	cb:回调函数
	arg:回调参数
	expireMillisecond:过期毫秒数
返回值:
	毫秒定时器

func (*Mgr) AddSecond

func (p *Mgr) AddSecond(cb OnFun, arg interface{}, expire int64) *Second

AddSecond 添加秒级定时器

参数:
	cb:回调函数
	arg:回调参数
	expire:过期秒数
返回值:
	秒定时器

func (*Mgr) ShadowTimeSecond

func (p *Mgr) ShadowTimeSecond() int64

ShadowTimeSecond 叠加偏移量的秒

func (*Mgr) Start

func (p *Mgr) Start(ctx context.Context, opts ...*Options) error

Start [NOTE] 处理定时器相关数据,必须与该outgoingTimeoutChan线性处理.如:在同一个goroutine select中处理数据

func (*Mgr) Stop

func (p *Mgr) Stop()

Stop 停止服务

type Millisecond

type Millisecond struct {
	Arg      interface{} // 参数
	Function OnFun       // 超时调用的函数
	// contains filtered or unexported fields
}

Millisecond 毫秒级定时器

func (*Millisecond) IsValid

func (p *Millisecond) IsValid() bool

IsValid 判断是否有效

type OnFun

type OnFun func(arg interface{})

OnFun 回调定时器函数(使用协程回调)

type Options

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

Options contains Options to configure instance. Each option can be set through setter functions. See documentation for each setter function for an explanation of the option.

func NewOptions

func NewOptions() *Options

NewOptions 新的Options

func (*Options) WithOutgoingTimerOutChan

func (p *Options) WithOutgoingTimerOutChan(timeoutChan chan<- interface{}) *Options

func (*Options) WithScanMillisecondDuration

func (p *Options) WithScanMillisecondDuration(scanMillisecondDuration *time.Duration) *Options

func (*Options) WithScanSecondDuration

func (p *Options) WithScanSecondDuration(scanSecondDuration *time.Duration) *Options

type Second

type Second struct {
	Millisecond
}

Second 秒级定时器

Jump to

Keyboard shortcuts

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