github.com/mailgun/holster/v4@v4.20.0/clock/system.go (about) 1 package clock 2 3 import "time" 4 5 type systemTime struct{} 6 7 func (st *systemTime) Now() time.Time { 8 return time.Now() 9 } 10 11 func (st *systemTime) Sleep(d time.Duration) { 12 time.Sleep(d) 13 } 14 15 func (st *systemTime) After(d time.Duration) <-chan time.Time { 16 return time.After(d) 17 } 18 19 type systemTimer struct { 20 t *time.Timer 21 } 22 23 func (st *systemTime) NewTimer(d time.Duration) Timer { 24 t := time.NewTimer(d) 25 return &systemTimer{t} 26 } 27 28 func (st *systemTime) AfterFunc(d time.Duration, f func()) Timer { 29 t := time.AfterFunc(d, f) 30 return &systemTimer{t} 31 } 32 33 func (t *systemTimer) C() <-chan time.Time { 34 return t.t.C 35 } 36 37 func (t *systemTimer) Stop() bool { 38 return t.t.Stop() 39 } 40 41 func (t *systemTimer) Reset(d time.Duration) bool { 42 return t.t.Reset(d) 43 } 44 45 type systemTicker struct { 46 t *time.Ticker 47 } 48 49 func (t *systemTicker) C() <-chan time.Time { 50 return t.t.C 51 } 52 53 func (t *systemTicker) Stop() { 54 t.t.Stop() 55 } 56 57 func (st *systemTime) NewTicker(d time.Duration) Ticker { 58 t := time.NewTicker(d) 59 return &systemTicker{t} 60 } 61 62 // Tick creates a new Ticker and returns ticker channel. 63 // Use sparingly or in unit tests as this potentially generates a resource leak. 64 // https://staticcheck.io/docs/checks#SA1015 65 func (st *systemTime) Tick(d time.Duration) <-chan time.Time { 66 //nolint: staticcheck // FIXME: SA1015: using time.Tick leaks the underlying ticker, consider using it only in endless functions, tests and the main package, and use time.NewTicker here 67 return time.Tick(d) 68 } 69 70 func (st *systemTime) Wait4Scheduled(count int, timeout time.Duration) bool { 71 panic("Not supported") 72 }