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 ¶ added in v0.10.5
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 ¶ added in v0.10.5
Running returns whether or not the timer is running. If the timer has timed out this will always return false.
func (*Model) Start ¶ added in v0.10.5
Start resumes the timer. Has no effect if the timer has timed out.
func (*Model) Stop ¶ added in v0.10.5
Stop pauses the timer. Has no effect if the timer has timed out.
func (*Model) Toggle ¶ added in v0.10.5
Toggle stops the timer if it's running and starts it if it's stopped.
type StartStopMsg ¶ added in v0.10.5
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 stopwatch that send 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 stopwatches, 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.