Documentation ¶
Overview ¶
Package timer provides a simple timeout component.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Model ¶
type Model struct { // How long until the timer expires. Timeout time.Duration // How long to wait before every tick. Defaults to 1 second. Interval time.Duration // contains filtered or unexported fields }
Model of the timer component.
func NewWithInterval ¶
NewWithInterval creates a new timer with the given timeout and tick interval.
func (Model) ID ¶
ID returns the model's identifier. This can be used to determine if messages belong to this timer instance when there are multiple timers.
func (Model) Running ¶
Running returns whether or not the timer is running. If the timer has timed out this will always return false.
type StartStopMsg ¶
type StartStopMsg struct { ID int // contains filtered or unexported fields }
StartStopMsg is used to start and stop the timer.
type TickMsg ¶
type TickMsg struct { // ID is the identifier of the timer that sends the message. This makes // it possible to determine which timer a tick belongs to when there // are multiple timers running. // // Note, however, that a timer will reject ticks from other timers, so // it's safe to flow all TickMsgs through all timers and have them still // behave appropriately. ID int // Timeout returns whether or not this tick is a timeout tick. You can // alternatively listen for TimeoutMsg. Timeout bool }
TickMsg is a message that is sent on every timer tick.
type TimeoutMsg ¶
type TimeoutMsg struct {
ID int
}
TimeoutMsg is a message that is sent once when the timer times out.
It's a convenience message sent alongside a TickMsg with the Timeout value set to true.