clock

package
v0.0.0-...-acbe8ed Latest Latest
Warning

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

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

Documentation

Overview

Package clock provides a time abstraction for deterministic testing.

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
	Since(t time.Time) time.Duration
	After(d time.Duration) <-chan time.Time
	Sleep(d time.Duration)
}

Clock is a source of time. Real wraps the standard library; Fake allows tests to advance time deterministically.

type Fake

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

Fake is a test Clock implementation that wraps clockwork.FakeClock. Use NewFake to create an instance, and Advance to move time forward. Goroutines blocked on After or Sleep will be woken when their deadline is passed by Advance.

func NewFake

func NewFake(start time.Time) *Fake

NewFake creates a new Fake clock starting at start.

func (*Fake) Advance

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

Advance moves the fake clock forward by d, waking any goroutines blocked on After or Sleep whose deadline has been passed.

func (*Fake) After

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

After returns a channel that fires after d of fake time has elapsed.

func (*Fake) Now

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

Now returns the current fake time.

func (*Fake) Since

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

Since returns the elapsed fake time since t.

func (*Fake) Sleep

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

Sleep blocks until d of fake time has elapsed via Advance calls.

type Real

type Real struct{}

Real is the production Clock implementation that delegates to the standard library.

func (Real) After

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

After returns a channel that fires after duration d.

func (Real) Now

func (Real) Now() time.Time

Now returns the current wall-clock time.

func (Real) Since

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

Since returns the elapsed time since t.

func (Real) Sleep

func (Real) Sleep(d time.Duration)

Sleep pauses the current goroutine for duration d.

Jump to

Keyboard shortcuts

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