clock

package
v0.9.0 Latest Latest
Warning

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

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

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package clock provides the emulator's clock: real by default, a fake advanceable clock under --deterministic or `gcpemu time advance` (NFR-REL-002).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Peek added in v0.9.0

func Peek(c Clock) time.Time

Peek reports c's current instant without advancing it, falling back to Now for clocks that are not Peekers.

Types

type Clock

type Clock interface {
	Now() time.Time
}

Clock reports the emulator's notion of time.

type Fake

type Fake struct {
	Step time.Duration
	// contains filtered or unexported fields
}

Fake is a deterministic clock that starts at a fixed instant and ticks forward by Step on every call to Now.

func NewFake

func NewFake() *Fake

NewFake returns a fake clock starting at 2026-01-01T00:00:00Z.

func (*Fake) Now

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

func (*Fake) Peek added in v0.9.0

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

Peek returns the instant the next Now will return, without advancing.

type Offset

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

Offset is a real clock that can be advanced for lifecycle/TTL tests.

func NewOffset

func NewOffset(base Clock) *Offset

NewOffset wraps base with an advanceable offset.

func (*Offset) Advance

func (o *Offset) Advance(d time.Duration)

Advance moves the clock forward by d.

func (*Offset) Now

func (o *Offset) Now() time.Time

func (*Offset) Peek added in v0.9.0

func (o *Offset) Peek() time.Time

Peek is Now without advancing a fake base clock.

type Peeker added in v0.9.0

type Peeker interface {
	Peek() time.Time
}

Peeker reports the current instant without advancing the clock. Background (wall-clock-driven) readers use it so that, under --deterministic, only request-driven reads move the fake clock.

type Real

type Real struct{}

Real is the wall clock.

func (Real) Now

func (Real) Now() time.Time

type Stopwatch added in v0.6.0

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

Stopwatch times short intervals such as a loopback round trip. Go's monotonic clock on Windows advances only every ~0.5ms, so a fast hop timed with time.Since reads as zero there; Stopwatch reads a high-resolution counter instead.

func StartStopwatch added in v0.6.0

func StartStopwatch() Stopwatch

StartStopwatch starts a Stopwatch now.

func (Stopwatch) Elapsed added in v0.6.0

func (s Stopwatch) Elapsed() time.Duration

Elapsed is the time since the Stopwatch started.

Jump to

Keyboard shortcuts

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