timer

package
v0.3.37 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const ALL_DAY bitset.BitSet = 0b1111111111111111111111111111111
View Source
const ALL_HOUR bitset.BitSet = 0b111111111111111111111111
View Source
const ALL_MINUTE bitset.BitSet = 0b111111111111111111111111111111111111111111111111111111111111
View Source
const ALL_MONTH bitset.BitSet = 0b111111111111
View Source
const ALL_SECOND bitset.BitSet = ALL_MINUTE
View Source
const ALL_WEEK bitset.BitSet = 0b1111111

Variables

This section is empty.

Functions

func SetTimeTestHandler added in v0.2.31

func SetTimeTestHandler(handler ITimeTestHandler)

func Stop added in v0.2.14

func Stop()

Types

type Head struct {
	Next *Head
	Prev *Head
	// contains filtered or unexported fields
}

func (*Head) Add

func (h *Head) Add(new *Head)

func (*Head) AddTail

func (h *Head) AddTail(new *Head)

func (*Head) Del

func (h *Head) Del(head *Head)

func (*Head) DelInit

func (h *Head) DelInit(pos *Head)

func (*Head) Empty

func (h *Head) Empty() bool

func (*Head) Entry

func (pos *Head) Entry(offset uintptr) unsafe.Pointer

func (*Head) FirstEntry

func (h *Head) FirstEntry(offset uintptr) unsafe.Pointer

func (*Head) FirstEntryOrNil

func (h *Head) FirstEntryOrNil(offset uintptr) unsafe.Pointer

func (*Head) ForEach

func (h *Head) ForEach(callback func(pos *Head))

func (*Head) ForEachPrev

func (h *Head) ForEachPrev(callback func(pos *Head))

func (*Head) ForEachPrevSafe

func (h *Head) ForEachPrevSafe(callback func(pos *Head))

func (*Head) ForEachSafe

func (h *Head) ForEachSafe(callback func(pos *Head))

func (*Head) Init

func (h *Head) Init()

初始化表头的函数,指向自己形成一个环

func (*Head) IsLast

func (h *Head) IsLast() bool

func (*Head) LastEntry

func (h *Head) LastEntry(offset uintptr) unsafe.Pointer

func (*Head) Len

func (h *Head) Len() int

func (*Head) Move

func (h *Head) Move(list *Head)

func (*Head) MoveTail

func (h *Head) MoveTail(list *Head)

func (*Head) NextEntry

func (pos *Head) NextEntry(offset uintptr) unsafe.Pointer

func (*Head) PrevEntry

func (pos *Head) PrevEntry(offset uintptr) unsafe.Pointer

func (*Head) Replace

func (h *Head) Replace(new *Head)

func (*Head) ReplaceInit

func (h *Head) ReplaceInit(new *Head)

func (*Head) RotateLeft

func (h *Head) RotateLeft()

type ITimeTestHandler added in v0.2.31

type ITimeTestHandler interface {
	Now() time.Time
	Get10Ms() time.Duration
}

type ITimerData added in v0.2.30

type ITimerData interface {
	Restore()
}

type Time

type Time struct {
	sync.Mutex
	// contains filtered or unexported fields
}

先使用sync.Mutex实现功能 后面使用cas优化

func (*Time) GetCallback added in v0.2.30

func (this *Time) GetCallback() func(TimeNoder)

func (*Time) GetDelay added in v0.2.19

func (this *Time) GetDelay() time.Duration

func (*Time) GetInterval added in v0.2.19

func (this *Time) GetInterval() time.Duration

func (*Time) Stop

func (this *Time) Stop()

一个timeNode节点有4个状态 1.存在于初始化链表中 2.被移动到tmp链表 3.1 和 3.2是if else的状态

3.1被移动到new链表
3.2直接执行

1和3.1状态是没有问题的 2和3.2状态会是没有锁保护下的操作,会有数据竞争

type TimeEventMsg added in v0.2.14

type TimeEventMsg struct {
	Callback  func(TimeNoder)
	TimeNoder TimeNoder
}

type TimeHandler added in v0.2.14

type TimeHandler interface {
	EventChan() <-chan TypeEventChan

	After(delay time.Duration, cb func(TimeNoder)) TimeNoder

	Schedule(interval time.Duration, cb func(TimeNoder), opts ...TimerOption) TimeNoder

	//expresion:1-2,3,4,5,6-12
	Cron(second, minute, hour, day, month, weekday interface{}, cb func(TimeNoder)) TimeNoder

	At(t time.Time, cb func(TimeNoder)) TimeNoder

	// 停止所有定时器
	StopTimer()

	// 删除handler
	DelTimer()

	PrintDebug()
}

func NewHandler added in v0.2.15

func NewHandler() TimeHandler

type TimeNoder

type TimeNoder interface {
	Stop()

	GetCallback() func(TimeNoder)

	GetDelay() time.Duration

	GetInterval() time.Duration
}

停止单个定时器

type Timer

type Timer interface {

	// 停止所有定时器
	Stop()

	Start()

	NewHandler() TimeHandler
}

定时器接口

func Instance

func Instance() Timer

func NewTimer

func NewTimer() Timer

type TimerOption added in v0.2.26

type TimerOption func(node *timeNode)

func WithDelay added in v0.2.26

func WithDelay(delay time.Duration) TimerOption

func WithLoop added in v0.2.26

func WithLoop(loop uint64) TimerOption

type TypeEventChan added in v0.2.14

type TypeEventChan interface{}

type TypeEventChan func(...interface{})

Jump to

Keyboard shortcuts

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