mirror of
https://github.com/prometheus/statsd_exporter.git
synced 2024-12-25 23:10:29 +00:00
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,
|
|
}
|
|
}
|