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