clock

package
v0.5.0 Latest Latest
Warning

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

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

Documentation

Overview

Package clock is the one time source of the server. Every instant the server reasons about (expiry, leases, schedules, created_at) is read here and passed on, to the domain as an argument and to SQL as a query parameter; SQL never reads the database's clock. A test that moves the fake clock therefore moves everything at once.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func After

func After(c Clock, d time.Duration) <-chan time.Time

After waits d on c: on c's own timers when it has them, otherwise on the wall clock.

Types

type Clock

type Clock interface {
	Now() time.Time
}

Clock tells the current time.

type Fake

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

Fake is a clock that stands still until it is moved, for tests. Its timers fire when the clock is moved past them, so time-dependent behaviour is tested without sleeping.

func NewFake

func NewFake(now time.Time) *Fake

NewFake returns a fake clock reading now.

func (*Fake) Advance

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

Advance moves the clock forward by d, firing every timer that falls due.

func (*Fake) After

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

After returns a channel that receives the clock's time once the clock has been moved d past its current time.

func (*Fake) Now

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

Now returns the clock's time.

func (*Fake) Set

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

Set moves the clock to t, forward or back, firing every timer that falls due.

type System

type System struct{}

System is the wall clock.

func (System) Now

func (System) Now() time.Time

Now returns the wall clock's time.

type Timers

type Timers interface {
	// After sends the clock's time on the returned channel once d has passed
	// on the clock.
	After(d time.Duration) <-chan time.Time
}

Timers is implemented by a clock that can be waited on, such as Fake, so that moving the clock fires what waits on it.

Jump to

Keyboard shortcuts

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