Documentation ¶
Overview ¶
Package timer provides various enhanced timer functions.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RandTicker ¶
RandTicker is just like time.Ticker, except that it adds randomness to the events.
func NewRandTicker ¶
func NewRandTicker(d, variance time.Duration) *RandTicker
NewRandTicker creates a new RandTicker. d is the duration, and variance specifies the variance. The ticker will tick every d +/- variance.
func (*RandTicker) Stop ¶
func (tkr *RandTicker) Stop()
Stop stops the ticker and closes the underlying channel.
type Timer ¶
type Timer struct {
// contains filtered or unexported fields
}
Timer provides timer functionality that can be controlled by the user. You start the timer by providing it a callback function, which it will call at the specified interval.
var t = timer.NewTimer(1e9) t.Start(KeepHouse) func KeepHouse() { // do house keeping work }
You can stop the timer by calling t.Stop, which is guaranteed to wait if KeepHouse is being executed.
You can create an untimely trigger by calling t.Trigger. You can also schedule an untimely trigger by calling t.TriggerAfter.
The timer interval can be changed on the fly by calling t.SetInterval. A zero value interval will cause the timer to wait indefinitely, and it will react only to an explicit Trigger or Stop.
func (*Timer) SetInterval ¶
SetInterval changes the wait interval. It will cause the timer to restart the wait.
func (*Timer) Stop ¶
func (tm *Timer) Stop()
Stop will stop the timer. It guarantees that the timer will not execute any more calls to keephouse once it has returned.
func (*Timer) Trigger ¶
func (tm *Timer) Trigger()
Trigger will cause the timer to immediately execute the keephouse function. It will then cause the timer to restart the wait.
func (*Timer) TriggerAfter ¶
TriggerAfter waits for the specified duration and triggers the next event.