timer

package
v0.0.0-...-1b4fa80 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

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

func NewTimerManager

func NewTimerManager() *Manager

func (*Manager) AddTimer

func (this *Manager) AddTimer(timerOuter TimerOuter, endTime uint32, interval uint32) uint32

AddTimer adds a timer to the timer manager. The timer manager will call the TimerOuter's TimeOut method when the timer expires. If the interval is not 0, the timer manager will add the timer back into the queue after it expires.

timerOuter: The TimerOuter to call TimeOut on when the timer expires.

endTime: The time in Unix time format when the timer should expire.

interval: How often to reschedule the timer in seconds. If 0, the timer will not be rescheduled.

Returns: The timer id of the timer that was added. This can be used to remove the timer later.

func (*Manager) RemoveTimer

func (this *Manager) RemoveTimer(timerId uint32)

func (*Manager) RunTimer

func (this *Manager) RunTimer()

RunTimer runs any timers that have expired.

If there are no timers in the queue, this function does nothing.

Otherwise, this function pulls the timer with the soonest expiration time from the queue and adds it to the list of timers to call TimeOut on.

If the timer's interval is not 0, the function reschedules the timer by adding it back into the queue with its updated expiration time.

Finally, the function calls TimeOut on all the timers that were pulled from the queue.

type Timer

type Timer struct {
	TimerOuter
	// contains filtered or unexported fields
}

type TimerCallback

type TimerCallback struct {
	CallBack func()
}

func (*TimerCallback) TimeOut

func (this *TimerCallback) TimeOut()

type TimerOuter

type TimerOuter interface {
	TimeOut()
}

type TimerQueue

type TimerQueue []*Timer

func (TimerQueue) Len

func (pq TimerQueue) Len() int

func (TimerQueue) Less

func (pq TimerQueue) Less(i, j int) bool

func (*TimerQueue) Pop

func (pq *TimerQueue) Pop() interface{}

func (*TimerQueue) Push

func (pq *TimerQueue) Push(x interface{})

func (TimerQueue) Swap

func (pq TimerQueue) Swap(i, j int)

Jump to

Keyboard shortcuts

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