Documentation ¶
Overview ¶
Package cherryTimeWheel file from https://github.com/RussellLuo/timingwheel
Index ¶
- func MSToTime(t int64) time.Time
- func NextId() uint64
- func TimeToMS(t time.Time) int64
- type DelayQueue
- type EverySchedule
- type FixedDateSchedule
- type Scheduler
- type TimeWheel
- func (tw *TimeWheel) AddEveryFunc(id uint64, d time.Duration, f func(), async ...bool) *Timer
- func (tw *TimeWheel) AfterFunc(id uint64, d time.Duration, f func(), async ...bool) *Timer
- func (tw *TimeWheel) BuildAfterFunc(d time.Duration, f func()) *Timer
- func (tw *TimeWheel) BuildEveryFunc(d time.Duration, f func(), async ...bool) *Timer
- func (tw *TimeWheel) NextId() uint64
- func (tw *TimeWheel) ScheduleFunc(id uint64, s Scheduler, f func(), async ...bool) *Timer
- func (tw *TimeWheel) Start()
- func (tw *TimeWheel) Stop()
- type Timer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DelayQueue ¶
type DelayQueue struct { C chan interface{} // contains filtered or unexported fields }
DelayQueue is an unbounded blocking queue of *Delayed* elements, in which an element can only be taken when its delay has expired. The head of the queue is the *Delayed* element whose delay expired furthest in the past.
func NewDelayQueue ¶
func NewDelayQueue(size int) *DelayQueue
NewDelayQueue creates an instance of delayQueue with the specified size.
func (*DelayQueue) Offer ¶
func (dq *DelayQueue) Offer(elem interface{}, expiration int64)
Offer inserts the element into the current queue.
func (*DelayQueue) Poll ¶
func (dq *DelayQueue) Poll(exitC chan struct{}, nowF func() int64)
Poll starts an infinite loop, in which it continually waits for an element to expire and then send the expired element to the channel C.
type EverySchedule ¶
type FixedDateSchedule ¶
type FixedDateSchedule struct {
Hour, Minute, Second int
}
type Scheduler ¶
type Scheduler interface { // Next returns the next execution time after the given (previous) time. // It will return a zero time if no next time is scheduled. // // All times must be UTC. Next(time.Time) time.Time }
Scheduler determines the execution plan of a task.
type TimeWheel ¶
type TimeWheel struct {
// contains filtered or unexported fields
}
TimeWheel is an implementation of Hierarchical Timing Wheels.
func NewTimeWheel ¶
NewTimeWheel creates an instance of TimeWheel with the given tick and wheelSize.
func (*TimeWheel) AddEveryFunc ¶
func (*TimeWheel) AfterFunc ¶
AfterFunc waits for the duration to elapse and then calls f in its own goroutine. It returns a Timer that can be used to cancel the call using its Stop method.
func (*TimeWheel) BuildAfterFunc ¶
func (*TimeWheel) BuildEveryFunc ¶
func (*TimeWheel) ScheduleFunc ¶
ScheduleFunc calls f (in its own goroutine) according to the execution plan scheduled by s. It returns a Timer that can be used to cancel the call using its Stop method.
If the caller want to terminate the execution plan halfway, it must stop the timer and ensure that the timer is stopped actually, since in the current implementation, there is a gap between the expiring and the restarting of the timer. The wait time for ensuring is short since the gap is very small.
Internally, ScheduleFunc will ask the first execution time (by calling s.Next()) initially, and create a timer if the execution time is non-zero. Afterwards, it will ask the next execution time each time f is about to be executed, and f will be called at the next execution time if the time is non-zero.
func (*TimeWheel) Stop ¶
func (tw *TimeWheel) Stop()
Stop stops the current timing wheel.
If there is any timer's task being running in its own goroutine, Stop does not wait for the task to complete before returning. If the caller needs to know whether the task is completed, it must coordinate with the task explicitly.
type Timer ¶
type Timer struct {
// contains filtered or unexported fields
}
Timer represents a single event. When the Timer expires, the given task will be executed.
func (*Timer) Stop ¶
Stop prevents the Timer from firing. It returns true if the call stops the timer, false if the timer has already expired or been stopped.
If the timer t has already expired and the t.task has been started in its own goroutine; Stop does not wait for t.task to complete before returning. If the caller needs to know whether t.task is completed, it must coordinate with t.task explicitly.