clock

package
v0.30.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: Apache-2.0 Imports: 2 Imported by: 7

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
}

Clock is where code reads the current time. A component receives one when it is built: the wall clock from New in production, a Fixed clock in a test.

func New added in v0.27.0

func New() Clock

New returns the wall clock. Production builds every service with it; a test passes a Fixed clock instead.

type Fixed added in v0.27.0

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

Fixed is a test clock that returns the instant it holds until Set or Advance moves it. It is safe for concurrent use, so a service under test can read it while the test moves it.

func NewFixed added in v0.27.0

func NewFixed(at time.Time) *Fixed

NewFixed returns a Fixed clock holding at.

func (*Fixed) Advance added in v0.27.0

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

Advance moves the instant the clock holds by d; a negative d moves it back.

func (*Fixed) Now added in v0.27.0

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

Now returns the instant the clock holds.

func (*Fixed) Set added in v0.27.0

func (f *Fixed) Set(at time.Time)

Set makes the clock hold at.

Jump to

Keyboard shortcuts

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