clock

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 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 gives code that depends on the time a replaceable source of it, so tests can control expiry, long-poll timeouts and timestamps exactly.

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 tells the time and makes timers.

type Fake

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

Fake is a clock that only moves when Advance is called.

func NewFake

func NewFake(t time.Time) *Fake

NewFake returns a fake clock set to t.

func (*Fake) Advance

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

Advance moves the clock forward by d and fires every timer that is now due.

func (*Fake) After

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

After fires once Advance moves the clock d or more past the current fake time.

func (*Fake) Next

func (f *Fake) Next() (time.Time, bool)

Next returns when the earliest timer waiting for the clock to move fires, and false when none waits.

func (*Fake) Now

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

Now returns the fake time.

func (*Fake) Waiters

func (f *Fake) Waiters() int

Waiters returns how many timers wait for the clock to move, so a test can move it once everything it expects is waiting.

type Real

type Real struct{}

Real is the system clock.

func (Real) After

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

After waits for d on the system clock.

func (Real) Now

func (Real) Now() time.Time

Now returns the current time.

Jump to

Keyboard shortcuts

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