github.com/xmidt-org/webpa-common@v1.11.9/clock/clock.go (about) 1 package clock 2 3 import "time" 4 5 // Interface represents a clock with the same core functionality available as in the stdlib time package 6 type Interface interface { 7 Now() time.Time 8 Sleep(time.Duration) 9 NewTicker(time.Duration) Ticker 10 NewTimer(time.Duration) Timer 11 } 12 13 type systemClock struct{} 14 15 func (sc systemClock) Now() time.Time { 16 return time.Now() 17 } 18 19 func (sc systemClock) Sleep(d time.Duration) { 20 time.Sleep(d) 21 } 22 23 func (sc systemClock) NewTicker(d time.Duration) Ticker { 24 return systemTicker{time.NewTicker(d)} 25 } 26 27 func (sc systemClock) NewTimer(d time.Duration) Timer { 28 return systemTimer{time.NewTimer(d)} 29 } 30 31 // System returns a clock backed by the time package 32 func System() Interface { 33 return systemClock{} 34 }