clock

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 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 defines the small Clock interface used by the runtime for testable time. Production wires real wall time; tests inject a Mock that they can step forward manually.

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
	AfterFunc(d time.Duration, f func()) Timer
}

Clock abstracts time.Now() and time.AfterFunc.

func Real

func Real() Clock

Real returns a Clock that uses wall-clock time.

type Mock

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

Mock is a controllable Clock for tests.

func NewMock

func NewMock(t time.Time) *Mock

NewMock returns a Mock initialised to t.

func (*Mock) Advance

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

Advance moves the clock forward by d, firing any expired timers.

func (*Mock) AfterFunc

func (m *Mock) AfterFunc(d time.Duration, f func()) Timer

AfterFunc schedules f to fire when the mock clock reaches now+d.

func (*Mock) Now

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

Now returns the mocked time.

type Timer

type Timer interface {
	Stop() bool
	Reset(d time.Duration) bool
}

Timer is the minimal subset of *time.Timer that callers need.

Jump to

Keyboard shortcuts

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