Documentation
¶
Overview ¶
Package timer provides functionality for measuring time.
Index ¶
Constants ¶
const ( // Nanosecond represents the nano second time.Duration. Nanosecond time.Duration = 1 // Microsecond represents the micro second time.Duration. Microsecond = 1000 * Nanosecond // Millisecond represents the milli second time.Duration. Millisecond = 1000 * Microsecond // Second represents the second time.Duration. Second = 1000 * Millisecond // Minute represents the minute time.Duration. Minute = 60 * Second // Hour represents the hour time.Duration. Hour = 60 * Minute )
Variables ¶
var Tag = "!use_cgo"
Tag is the sleep type.
Functions ¶
func After ¶
After waits for the duration to elapse and then sends the current time on the returned channel. It is equivalent to NewTimer(d).C. The underlying Timer is not recovered by the garbage collector until the timer fires. If efficiency is a concern, use NewTimer instead and call Timer.Stop if the timer is no longer needed.
func Sleep ¶
Sleep pauses the current goroutine for at least the duration d. A negative or zero duration causes Sleep to return immediately.
func Tick ¶
Tick is a convenience wrapper for NewTicker providing access to the ticking channel only. While Tick is useful for clients that have no need to shut down the Ticker, be aware that without a way to shut it down the underlying Ticker cannot be recovered by the garbage collector; it "leaks". Unlike NewTicker, Tick will return nil if d <= 0.
Types ¶
type Ticker ¶
type Ticker struct { C <-chan time.Time // The channel on which the ticks are delivered. // contains filtered or unexported fields }
A Ticker holds a channel that delivers `ticks' of a clock at intervals.
func NewTicker ¶
NewTicker returns a new Ticker containing a channel that will send the time with a period specified by the duration argument. It adjusts the intervals or drops ticks to make up for slow receivers. The duration d must be greater than zero; if not, NewTicker will panic. Stop the ticker to release associated resources.
type Timer ¶
The Timer type represents a single event. When the Timer expires, the current time will be sent on C, unless the Timer was created by AfterFunc. A Timer must be created with NewTimer or AfterFunc.
func AfterFunc ¶
AfterFunc waits for the duration to elapse and then calls f in its own goroutine. It returns a Timer that can be used to cancel the call using its Stop method.
func NewTimer ¶
NewTimer creates a new Timer that will send the current time on its channel after at least duration d.