Documentation ¶
Overview ¶
Package asynctimer provides asynchronous timer function, which is implemented by time wheel.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidParam denotes that param is invalid. ErrInvalidParam = errors.New("asynctimer: param is invalid") // ErrShortDelay denotes that timer's delay is too short. ErrShortDelay = errors.New("asynctimer: delay time is too short") )
Functions ¶
func Add ¶
Add adds timer to the default time wheel. Timer becomes effective after having been added. Note that time precision is 1 second, if the required precision is less than 1s, a custom time wheel should be used.
Types ¶
type Callback ¶
type Callback func(data any)
Callback is asynchronous callback function when timer expired.
type TimeWheel ¶
type TimeWheel struct {
// contains filtered or unexported fields
}
TimeWheel manages all async timers.
func NewTimeWheel ¶
NewTimeWheel creates a time wheel which manages async timers. Time wheel's round time is equal to slotNum*interval. Interval means duration of each tick of time wheel, slotNum means numbers of slots in a round.
func (*TimeWheel) Add ¶
Add adds timer to time wheel. Timer becomes effective after having been added to time wheel.
func (*TimeWheel) Del ¶
Del deletes timer from time wheel. After having been deleted from the wheel, timer become invalid, and the resource will be released.
type Timer ¶
type Timer struct {
// contains filtered or unexported fields
}
Timer is an async timer.