clock

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: CC0-1.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 provides the injected time source. It is the only package allowed to call time.Now.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clock

type Clock interface {
	// Now returns the current instant.
	Now() time.Time
	// After returns a channel that receives the time once d has elapsed.
	// Intended for schedulers only.
	After(d time.Duration) <-chan time.Time
}

Clock is the time source every other package receives by injection.

type Fake

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

Fake is a manually driven Clock for tests. It is safe for concurrent use.

func NewFake

func NewFake(t time.Time) *Fake

NewFake returns a Fake whose current time is t.

func (*Fake) Advance

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

Advance moves the clock forward by d.

func (*Fake) After

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

After returns a channel that receives the fake time at which the deadline was reached. A non-positive d is ready immediately.

func (*Fake) Now

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

Now returns the fake's current time.

func (*Fake) Set

func (f *Fake) Set(t time.Time)

Set moves the clock to t (backwards is allowed) and fires every waiter whose deadline is at or before t.

type Real

type Real struct{}

Real is the wall-clock implementation of Clock.

func (Real) After

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

After is time.After.

func (Real) Now

func (Real) Now() time.Time

Now returns the current wall-clock time.

Jump to

Keyboard shortcuts

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