Documentation ¶
Index ¶
- type Clock
- type FakeClock
- func (f *FakeClock) After(d time.Duration) <-chan time.Time
- func (f *FakeClock) HasWaiters() bool
- func (f *FakeClock) NewTicker(d time.Duration) Ticker
- func (f *FakeClock) NewTimer(d time.Duration) Timer
- func (f *FakeClock) SetTime(t time.Time)
- func (f *FakeClock) Sleep(d time.Duration)
- func (f *FakeClock) Step(d time.Duration)
- type FakePassiveClock
- type IntervalClock
- func (*IntervalClock) After(d time.Duration) <-chan time.Time
- func (*IntervalClock) NewTicker(d time.Duration) Ticker
- func (*IntervalClock) NewTimer(d time.Duration) Timer
- func (i *IntervalClock) Now() time.Time
- func (i *IntervalClock) Since(ts time.Time) time.Duration
- func (*IntervalClock) Sleep(d time.Duration)
- type PassiveClock
- type RealClock
- type Ticker
- type Timer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Clock ¶
type Clock interface { PassiveClock After(time.Duration) <-chan time.Time NewTimer(time.Duration) Timer Sleep(time.Duration) NewTicker(time.Duration) Ticker }
Clock allows for injecting fake or real clocks into code that needs to do arbitrary things based on time.
type FakeClock ¶
type FakeClock struct { FakePassiveClock // contains filtered or unexported fields }
FakeClock implements Clock, but returns an arbitrary time.
func (*FakeClock) After ¶
After is the Fake version of time.After(d).
func (*FakeClock) HasWaiters ¶
HasWaiters returns true if After has been called on f but not yet satisfied (so you can write race-free tests).
func (*FakeClock) NewTicker ¶
NewTicker returns a new Ticker.
func (*FakeClock) NewTimer ¶
NewTimer is the Fake version of time.NewTimer(d).
func (*FakeClock) SetTime ¶
SetTime sets the time on a FakeClock.
func (*FakeClock) Sleep ¶
Sleep pauses the FakeClock for duration d.
type FakePassiveClock ¶
type FakePassiveClock struct {
// contains filtered or unexported fields
}
FakePassiveClock implements PassiveClock, but returns an arbitrary time.
func NewFakePassiveClock ¶
func NewFakePassiveClock(t time.Time) *FakePassiveClock
NewFakePassiveClock returns a new FakePassiveClock.
func (*FakePassiveClock) SetTime ¶
func (f *FakePassiveClock) SetTime(t time.Time)
SetTime sets the time on the FakePassiveClock.
type IntervalClock ¶
IntervalClock implements Clock, but each invocation of Now steps the clock forward the specified duration
func (*IntervalClock) After ¶
func (*IntervalClock) After(d time.Duration) <-chan time.Time
After is currently unimplemented, will panic. TODO: make interval clock use FakeClock so this can be implemented.
func (*IntervalClock) NewTicker ¶
func (*IntervalClock) NewTicker(d time.Duration) Ticker
NewTicker is currently unimplemented, will panic. TODO: make interval clock use FakeClock so this can be implemented.
func (*IntervalClock) NewTimer ¶
func (*IntervalClock) NewTimer(d time.Duration) Timer
NewTimer is currently unimplemented, will panic. TODO: make interval clock use FakeClock so this can be implemented.
func (*IntervalClock) Since ¶
func (i *IntervalClock) Since(ts time.Time) time.Duration
Since returns time since the time in i.
func (*IntervalClock) Sleep ¶
func (*IntervalClock) Sleep(d time.Duration)
Sleep is currently unimplemented; will panic.
type PassiveClock ¶
PassiveClock allows for injecting fake or real clocks into code that needs to read the current time but does not support scheduling activity in the future.
type RealClock ¶
type RealClock struct{}
RealClock really calls time.Now()
func (RealClock) After ¶
After is the same as time.After(d).
func (RealClock) NewTicker ¶
NewTicker returns a new Ticker.
func (RealClock) NewTimer ¶
NewTimer returns a new Timer.
func (RealClock) Since ¶
Since returns time since the specified timestamp.
type Ticker ¶
Ticker defines the Ticker interface