clock

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 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 abstracts time so that timers can be driven deterministically in tests.

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

Clock is the source of time for the reporter.

func Real

func Real() Clock

Real returns a Clock backed by the system clock.

type Fake

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

Fake is a Clock whose time only moves when Advance is called.

func NewFake

func NewFake(start time.Time) *Fake

NewFake returns a Fake clock set to start.

func (*Fake) Advance

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

Advance moves the fake time forward by d and fires every timer that became due.

func (*Fake) After

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

After returns a channel that receives the fake time once it has advanced by d. A non-positive d fires immediately.

func (*Fake) Now

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

Now returns the fake time.

Jump to

Keyboard shortcuts

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