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 New ¶
New creates a new timer with the given timeout and default 1s interval.
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.
func (*Model) Start ¶
Start resumes the timer. Has no effect if the timer has timed out.
func (*Model) Stop ¶
Stop pauses the timer. Has no effect if the timer has timed out.
func (Model) Timedout ¶
Timedout returns whether or not the timer has timed out.
func (*Model) Toggle ¶
Toggle stops the timer if it's running and starts it if it's stopped.
func (Model) Update ¶
Update handles the timer tick.
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
// contains filtered or unexported fields
}
TickMsg is a message that is sent on every timer tick.
Source Files
¶
- timer.go