Documentation ¶
Index ¶
Constants ¶
const ( // ISO8601Micro is the default joda datetime print format, which is useful // when interacting with services written in Java. ISO8601Micro = `2006-01-02T15:04:05.000-07:00` )
Many common formats can be found in go's time package, such as ANSIC and RFC, so check before adding any format to this file.
Additional formats are described here for convenience.
Variables ¶
This section is empty.
Functions ¶
func After ¶ added in v1.5.0
After is a safer, but more expensive alternative to time.After.
After waits for the duration to elapse and then sends the current time on the returned channel. If the context gets canceled before the duration elapses, no message is sent on the returned channel.
The returned channel is never closed.
func DurationToMillis ¶
DurationToMillis returns d in terms of milliseconds.
func FromMilliseconds ¶
FromMilliseconds converts time in milliseconds since epoch to time.Time
func ToMilliseconds ¶
ToMilliseconds returns time in milliseconds since epoch
Types ¶
type Clock ¶
type Clock interface { // Now is the time on this Clock. Now() time.Time // Since returns the size of the interval between the time.Time of Clock.Now // and the provided time.Time. Since(time.Time) time.Duration // SinceMS returns the same thing as Since, but converted to milliseconds. SinceMS(time.Time) int }
Clock provides a mock-able interface of some of the standard library time package functions, like time.Now and time.Since. A default implementation is provided by SystemClock which defers to the time package functions.
func SystemClock ¶
func SystemClock() Clock
SystemClock creates a Clock that is implemented by deferring to the standard library time package.
type Sleeper ¶
A Sleeper is a useful way for calling time.Sleep in a mockable way for tests.
func NewSleeper ¶
func NewSleeper() Sleeper
NewSleeper creates a Sleeper that will actually call time.Sleep under the hood, causing the program to sleep.
type StopTimerFunc ¶ added in v1.6.0
type StopTimerFunc func() bool
StopTimerFunc is used to stop a time.Timer.
Calling StopTimerFunc prevents its time.Timer from firing. Returns true if the call stops the timer, false if the timer has already expired. or has been stopped.
https://pkg.go.dev/time#Timer.Stop
func SafeTimer ¶ added in v1.6.0
func SafeTimer(duration time.Duration) (*time.Timer, StopTimerFunc)
SafeTimer creates a time.Timer and a StopTimerFunc, forcing the caller to deal with the otherwise potential resource leak. Encourages safe use of a time.Timer in a select statement, but without the overhead of a context.Context.
Typical usage:
t, stop := libtime.SafeTimer(interval) defer stop() for { select { case <- t.C: foo() case <- otherC : return } }
Does not panic if duration is <= 0, instead assuming the smallest positive value.
Directories ¶
Path | Synopsis |
---|---|
Package decay provides a generalized exponential backoff retry implementation.
|
Package decay provides a generalized exponential backoff retry implementation. |