|
|
|
@ -14,7 +14,6 @@ import (
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// TODO(chef): [feat] 增加Clock::Sleep,内部用Timer实现等待
|
|
|
|
|
// TODO(chef): [feat] 增加Clock::NewTicker
|
|
|
|
|
|
|
|
|
|
type Clock interface {
|
|
|
|
@ -24,6 +23,7 @@ type Clock interface {
|
|
|
|
|
//
|
|
|
|
|
Now() time.Time
|
|
|
|
|
NewTimer(d time.Duration) *Timer
|
|
|
|
|
Sleep(d time.Duration)
|
|
|
|
|
|
|
|
|
|
// Add Set ...
|
|
|
|
|
//
|
|
|
|
@ -59,6 +59,10 @@ func (c *stdClock) NewTimer(d time.Duration) *Timer {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *stdClock) Sleep(d time.Duration) {
|
|
|
|
|
time.Sleep(d)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *stdClock) Add(d time.Duration) {
|
|
|
|
|
// noop
|
|
|
|
|
}
|
|
|
|
@ -95,6 +99,11 @@ func (fc *fakeClock) NewTimer(d time.Duration) *Timer {
|
|
|
|
|
return t
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (fc *fakeClock) Sleep(d time.Duration) {
|
|
|
|
|
// TODO(chef): [feat] 实现和add、set挂钩的Sleep,内部用Timer实现等待
|
|
|
|
|
// 当前的使用场景都是测试场景,直接快速跳过Sleep以及能够满足需求
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (fc *fakeClock) Add(d time.Duration) {
|
|
|
|
|
fc.mu.Lock()
|
|
|
|
|
fc.now = fc.now.Add(d)
|
|
|
|
|