clock

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

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
	NewTimer(d time.Duration) Timer
	After(d time.Duration) <-chan time.Time
}

Clock abstracts time operations for deterministic testing.

func System

func System() Clock

System returns a Clock backed by the real system time.

type MockClock

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

MockClock is a deterministic clock for testing.

func Mock

func Mock(now time.Time) *MockClock

Mock returns a manually-controlled Clock for tests.

func (*MockClock) Advance

func (m *MockClock) Advance(d time.Duration)

Advance moves the clock forward by d and fires any expired timers.

func (*MockClock) After

func (m *MockClock) After(d time.Duration) <-chan time.Time

func (*MockClock) NewTimer

func (m *MockClock) NewTimer(d time.Duration) Timer

func (*MockClock) Now

func (m *MockClock) Now() time.Time

func (*MockClock) Set

func (m *MockClock) Set(t time.Time)

Set sets the clock to an absolute time and fires any expired timers.

func (*MockClock) Since

func (m *MockClock) Since(t time.Time) time.Duration

type Timer

type Timer interface {
	C() <-chan time.Time
	Stop() bool
	Reset(d time.Duration) bool
}

Timer abstracts time.Timer for testability.

Jump to

Keyboard shortcuts

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