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

clock

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

README

core/clock

AutoDoc's time. The daemon builds one Clock and hands it to every core package that records a time or compares with one, through that package's WithClock option.

Name What
Clock func() time.Time; Now() reads it, and the zero Clock is time.Now
Sleep(ctx, d) waits for d or ctx, and reports whether d elapsed

What goes through the Clock: a time that is stored (an updated_at, an event's time), or compared with one (a retry deadline, a change log's age).

What stays on the monotonic clock: a latency measured for a log line (time.Since(start)), and the timers a loop waits on. A test's Clock does not move them.

Safe for concurrent use. A test's Clock must be too.

Documentation

Overview

Package clock is AutoDoc's time: the one Clock a daemon builds and hands to every core package that records a time or compares with one, and a context-aware Sleep.

A Clock reads wall time for what is stored or compared with what is stored (an updated_at, a retry deadline). A latency measured for a log line (time.Since a start) stays on the monotonic clock: a test's Clock does not move it.

Concurrency: a Clock is a function value; time.Now is safe for concurrent use, and a test's Clock must be too. Sleep may be called from any goroutine.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Sleep

func Sleep(ctx context.Context, d time.Duration) bool

Sleep waits for d or ctx, whichever ends first, and reports whether d elapsed.

Types

type Clock

type Clock func() time.Time

Clock is the time now: time.Now, or a test's. The zero Clock is time.Now.

func (Clock) Now

func (c Clock) Now() time.Time

Now is the clock's time; a nil Clock reads time.Now.

Jump to

Keyboard shortcuts

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