package clock
import "k8s.io/klog/v2/internal/clock"
Index ¶
- type Clock
- type PassiveClock
- type RealClock
- func (RealClock) After(d time.Duration) <-chan time.Time
- func (RealClock) AfterFunc(d time.Duration, f func()) Timer
- func (RealClock) NewTicker(d time.Duration) Ticker
- func (RealClock) NewTimer(d time.Duration) Timer
- func (RealClock) Now() time.Time
- func (RealClock) Since(ts time.Time) time.Duration
- func (RealClock) Sleep(d time.Duration)
- type Ticker
- type Timer
- type WithDelayedExecution
- type WithTickerAndDelayedExecution
Types ¶
type Clock ¶
type Clock interface {
PassiveClock
// After returns the channel of a new Timer.
// This method does not allow to free/GC the backing timer before it fires. Use
// NewTimer instead.
After(d time.Duration) <-chan time.Time
// NewTimer returns a new Timer.
NewTimer(d time.Duration) Timer
// Sleep sleeps for the provided duration d.
// Consider making the sleep interruptible by using 'select' on a context channel and a timer channel.
Sleep(d time.Duration)
// NewTicker returns a new Ticker.
NewTicker(time.Duration) Ticker
}
Clock allows for injecting fake or real clocks into code that needs to do arbitrary things based on time.
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). This method does not allow to free/GC the backing timer before it fires. Use NewTimer instead.
func (RealClock) AfterFunc ¶
AfterFunc is the same as time.AfterFunc(d, f).
func (RealClock) NewTicker ¶
NewTicker returns a new Ticker.
func (RealClock) NewTimer ¶
NewTimer is the same as time.NewTimer(d)
func (RealClock) Now ¶
Now returns the current time.
func (RealClock) Since ¶
Since returns time since the specified timestamp.
func (RealClock) Sleep ¶
Sleep is the same as time.Sleep(d) Consider making the sleep interruptible by using 'select' on a context channel and a timer channel.
type Ticker ¶
Ticker defines the Ticker interface.
type Timer ¶
Timer allows for injecting fake or real timers into code that needs to do arbitrary things based on time.
type WithDelayedExecution ¶
type WithDelayedExecution interface {
Clock
// AfterFunc executes f in its own goroutine after waiting
// for d duration and returns a Timer whose channel can be
// closed by calling Stop() on the Timer.
AfterFunc(d time.Duration, f func()) Timer
}
WithDelayedExecution allows for injecting fake or real clocks into code that needs to make use of AfterFunc functionality.
type WithTickerAndDelayedExecution ¶
type WithTickerAndDelayedExecution interface {
Clock
// AfterFunc executes f in its own goroutine after waiting
// for d duration and returns a Timer whose channel can be
// closed by calling Stop() on the Timer.
AfterFunc(d time.Duration, f func()) Timer
}
WithTickerAndDelayedExecution allows for injecting fake or real clocks into code that needs Ticker and AfterFunc functionality
Source Files ¶
clock.go
Directories ¶
| Path | Synopsis |
|---|---|
| internal/clock/testing |
- Version
- v2.140.0 (latest)
- Published
- Mar 3, 2026
- Platform
- linux/amd64
- Imports
- 1 packages
- Last checked
- 9 hours ago –
Tools for package owners.