statsd_exporter/pkg/clock/clock.go
Ivan Mikheykin 699c11ca11 Rework tests to not depend on actual wall clocks
Signed-off-by: Ivan Mikheykin <ivan.mikheykin@flant.com>
2018-12-19 08:24:25 +03:00

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,
}
}