clock

package
v0.1.0-alpha.8 Latest Latest
Warning

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

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

Documentation

Overview

Package clock abstracts time for testability. Every timeout, ticker or deadline in daemon control loops MUST go through a Clock so simcluster and unit tests can drive time deterministically with Fake.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clock

type Clock interface {
	Now() time.Time
	// After behaves like time.After.
	After(d time.Duration) <-chan time.Time
	// NewTicker behaves like time.NewTicker.
	NewTicker(d time.Duration) Ticker
	// Sleep blocks for d.
	Sleep(d time.Duration)
}

Clock is the minimal time surface control loops need.

type Fake

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

Fake is a deterministic Clock driven by Advance. Timers fire synchronously inside Advance, in chronological order.

func NewFake

func NewFake() *Fake

NewFake starts at a fixed, arbitrary epoch for reproducible tests.

func (*Fake) Advance

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

Advance moves the clock forward, firing due timers/tickers in order.

func (*Fake) After

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

func (*Fake) NewTicker

func (f *Fake) NewTicker(d time.Duration) Ticker

func (*Fake) Now

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

func (*Fake) Sleep

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

type Real

type Real struct{}

Real is the production clock.

func (Real) After

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

func (Real) NewTicker

func (Real) NewTicker(d time.Duration) Ticker

func (Real) Now

func (Real) Now() time.Time

func (Real) Sleep

func (Real) Sleep(d time.Duration)

type Ticker

type Ticker interface {
	C() <-chan time.Time
	Stop()
}

Ticker mirrors time.Ticker behind an interface.

Jump to

Keyboard shortcuts

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