Help us shape the future of Go! Take the 2026 Go Developer Survey

clock

package
v0.16.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2026 License: AGPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Package clock provides the time source core depends on.

The reconciler's backoff (R-149) and the give-up window (R-150) are both time dependent, and a test that proves a ten-failure threshold inside a thirty-minute window must not take thirty minutes. Every core component takes a Clock rather than calling time.Now.

Index

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, always UTC (design 00 §3.5).
	Now() time.Time
	// Since is shorthand for Now().Sub(t).
	Since(t time.Time) time.Duration
	// After behaves like time.After.
	After(d time.Duration) <-chan time.Time
	// Sleep blocks for d.
	Sleep(d time.Duration)
}

Clock is a time source.

type Fake

type Fake struct {
	// contains filtered or unexported fields
}

Fake is a manually advanced clock for tests.

After returns a channel that fires when the fake clock is advanced past the deadline, so a test drives elapsed time explicitly instead of sleeping.

func NewFake

func NewFake(t time.Time) *Fake

NewFake returns a Fake set to t, or to a fixed arbitrary instant if t is zero.

func (*Fake) Advance

func (f *Fake) Advance(d time.Duration)

Advance moves the clock forward and fires any waiter whose deadline passed.

func (*Fake) After

func (f *Fake) After(d time.Duration) <-chan time.Time

func (*Fake) Now

func (f *Fake) Now() time.Time

func (*Fake) Set

func (f *Fake) Set(t time.Time)

Set moves the clock to an absolute time. It fires waiters the same way Advance does when moving forward, and fires none when moving backward.

func (*Fake) Since

func (f *Fake) Since(t time.Time) time.Duration

func (*Fake) Sleep

func (f *Fake) Sleep(d time.Duration)

Sleep on a Fake returns immediately after advancing the clock. A test that genuinely wants to block should use After and Advance from another goroutine.

type System

type System struct{}

System is the real clock.

func (System) After

func (System) After(d time.Duration) <-chan time.Time

func (System) Now

func (System) Now() time.Time

func (System) Since

func (System) Since(t time.Time) time.Duration

func (System) Sleep

func (System) Sleep(d time.Duration)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL