forked from mirrors/statsd_exporter
699c11ca11
Signed-off-by: Ivan Mikheykin <ivan.mikheykin@flant.com>
28 lines
428 B
Go
28 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,
|
|
}
|
|
}
|