clock

package
v0.6.76 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: AGPL-3.0, Apache-2.0, MIT Imports: 2 Imported by: 0

Documentation

Overview

Package clock abstracts time so the daemon's timers (idle detection, settling, credential rotation) can be driven by a fake clock 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
	// Since is Now().Sub(t), using the monotonic reading when t carries one.
	Since(t time.Time) time.Duration
	// NewTicker returns a ticker whose channel fires every d.
	NewTicker(d time.Duration) Ticker
	// After fires once after d.
	After(d time.Duration) <-chan time.Time
}

Clock is the subset of the time package the daemon uses.

type Fake

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

Fake is a manually advanced clock. Tickers and timers fire synchronously from Advance.

func NewFake

func NewFake(start time.Time) *Fake

NewFake returns a fake clock starting at start.

func (*Fake) Advance

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

Advance moves the clock forward, firing due timers and tickers.

func (*Fake) After

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

func (*Fake) NewTicker

func (f *Fake) NewTicker(d time.Duration) Ticker

func (*Fake) Now

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

func (*Fake) Set

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

Set jumps the clock to t without firing tickers in between (like a wall clock jump after a memory restore).

func (*Fake) Since

func (f *Fake) Since(t time.Time) time.Duration

type Real

type Real struct{}

Real is the wall clock.

func (Real) After

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

func (Real) NewTicker

func (Real) NewTicker(d time.Duration) Ticker

func (Real) Now

func (Real) Now() time.Time

func (Real) Since

func (Real) Since(t time.Time) time.Duration

type Ticker

type Ticker interface {
	C() <-chan time.Time
	Stop()
}

Ticker is a stoppable ticker.

Jump to

Keyboard shortcuts

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