clock/clock.go

38 строки
1.1 KiB
Go
Исходник Постоянная ссылка Обычный вид История

2015-12-31 04:17:02 +03:00
package clock
import (
"time"
)
// The Clock interface provides time-based functionality. It should be used
// rather than the `time` package in situations where you want to mock things.
type Clock interface {
Now() time.Time
After(d time.Duration) <-chan time.Time
Sleep(d time.Duration)
Tick(d time.Duration) <-chan time.Time
AfterFunc(d time.Duration, f func()) Timer
NewTimer(d time.Duration) Timer
NewTicker(d time.Duration) Ticker
Since(t time.Time) time.Duration
2015-12-31 04:17:02 +03:00
}
// The Timer is an interface for time.Timer, and can also be swapped in mocks.
// This *does* change its API so that it can fit into an interface -- rather
// than using the channel at .C, you should call Chan() and use the
// returned channel just as you would .C.
type Timer interface {
Chan() <-chan time.Time
Reset(d time.Duration) bool
Stop() bool
}
// The Ticker is an interface for time.Ticker, and can also be swapped in mocks.
2015-12-31 04:17:02 +03:00
// This *does* change its API so that it can fit into an interface -- rather
// than using the channel at .C, you should call Chan() and use the
// returned channel just as you would .C.
type Ticker interface {
Chan() <-chan time.Time
Stop()
}