forked from mirrors/statsd_exporter
29 lines
428 B
Go
29 lines
428 B
Go
|
package clock
|
||
|
|
||
|
import (
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
var ClockInstance *Clock
|
||
|
|
||
|
type Clock struct {
|
||
|
Instant time.Time
|
||
|
TickerCh chan time.Time
|
||
|
}
|
||
|
|
||
|
func Now() time.Time {
|
||
|
if ClockInstance == nil {
|
||
|
return time.Now()
|
||
|
}
|
||
|
return ClockInstance.Instant
|
||
|
}
|
||
|
|
||
|
func NewTicker(d time.Duration) *time.Ticker {
|
||
|
if ClockInstance == nil || ClockInstance.TickerCh == nil {
|
||
|
return time.NewTicker(d)
|
||
|
}
|
||
|
return &time.Ticker{
|
||
|
C: ClockInstance.TickerCh,
|
||
|
}
|
||
|
}
|