2019-11-24 20:27:59 +00:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import "time"
|
|
|
|
|
2020-05-02 05:06:39 +00:00
|
|
|
// Clock is an interface for a clock.
|
2019-11-24 20:27:59 +00:00
|
|
|
type Clock interface {
|
|
|
|
Now() time.Time
|
|
|
|
After(d time.Duration) <-chan time.Time
|
|
|
|
}
|
|
|
|
|
2020-05-02 05:06:39 +00:00
|
|
|
// RealClock is the implementation of a clock for production code.
|
2019-11-24 20:27:59 +00:00
|
|
|
type RealClock struct{}
|
|
|
|
|
2020-05-02 05:06:39 +00:00
|
|
|
// Now return the current time.
|
2019-11-24 20:27:59 +00:00
|
|
|
func (RealClock) Now() time.Time {
|
|
|
|
return time.Now()
|
|
|
|
}
|
|
|
|
|
2020-05-02 05:06:39 +00:00
|
|
|
// After return a channel receiving the time after the defined duration.
|
2019-11-24 20:27:59 +00:00
|
|
|
func (RealClock) After(d time.Duration) <-chan time.Time {
|
|
|
|
return time.After(d)
|
|
|
|
}
|