Documentation ¶
Overview ¶
Package 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.
Index ¶
Constants ¶
const ( STOP typeAction = iota RESET TRIGGER )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Timer ¶
type Timer struct {
// contains filtered or unexported fields
}
Timer implements the timer functionality described above.
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.