Documentation
¶
Overview ¶
Package timeutil provides a testable abstraction over time operations.
Index ¶
- type Clock
- type MockClock
- func (c *MockClock) Advance(d time.Duration)
- func (c *MockClock) After(d time.Duration) <-chan time.Time
- func (c *MockClock) NewTicker(d time.Duration) Ticker
- func (c *MockClock) NewTimer(d time.Duration) Timer
- func (c *MockClock) Now() time.Time
- func (c *MockClock) Set(t time.Time)
- func (c *MockClock) Since(t time.Time) time.Duration
- func (c *MockClock) Sleep(d time.Duration)
- func (c *MockClock) Sleeps() []time.Duration
- func (c *MockClock) Until(t time.Time) time.Duration
- type MockTicker
- type MockTimer
- type RealClock
- func (RealClock) After(d time.Duration) <-chan time.Time
- func (RealClock) NewTicker(d time.Duration) Ticker
- func (RealClock) NewTimer(d time.Duration) Timer
- func (RealClock) Now() time.Time
- func (RealClock) Since(t time.Time) time.Duration
- func (RealClock) Sleep(d time.Duration)
- func (RealClock) Until(t time.Time) time.Duration
- 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 {
// Now returns the current time.
Now() time.Time
// Since returns the duration since t.
Since(t time.Time) time.Duration
// Until returns the duration until t.
Until(t time.Time) time.Duration
// Sleep pauses for the specified duration.
Sleep(d time.Duration)
// After waits for the duration to elapse and then sends the current time.
After(d time.Duration) <-chan time.Time
// NewTimer creates a new Timer that will send the current time
// on its channel after at least duration d.
NewTimer(d time.Duration) Timer
// NewTicker returns a new Ticker containing a channel that will
// send the time with a period specified by the duration argument.
NewTicker(d time.Duration) Ticker
}
Clock provides an abstraction over time operations for testability.
type MockClock ¶
type MockClock struct {
// contains filtered or unexported fields
}
MockClock is a manually controlled clock for testing.
func NewMockClock ¶
NewMockClock creates a new MockClock set to the given time.
func (*MockClock) Advance ¶
Advance moves the mock clock forward by the given duration and fires any expired timers/tickers.
type MockTicker ¶
type MockTicker struct {
// contains filtered or unexported fields
}
MockTicker is a manually controlled ticker for testing.
func (*MockTicker) Reset ¶
func (t *MockTicker) Reset(d time.Duration)
Reset stops a ticker and resets its period to the specified duration.
func (*MockTicker) Trigger ¶
func (t *MockTicker) Trigger(now time.Time)
Trigger manually sends a tick with the given time.
type MockTimer ¶
type MockTimer struct {
// contains filtered or unexported fields
}
MockTimer is a manually controlled timer for testing.
type RealClock ¶
type RealClock struct{}
RealClock implements Clock using the standard time package.
type Ticker ¶
type Ticker interface {
// C returns the channel on which the ticks are delivered.
C() <-chan time.Time
// Stop turns off a ticker.
Stop()
// Reset stops a ticker and resets its period to the specified duration.
Reset(d time.Duration)
}
Ticker holds a channel that delivers "ticks" of a clock at intervals.