clock

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2026 License: Apache-2.0 Imports: 5 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 monotonic clocks for live execution and deterministic replay.

Index

Constants

This section is empty.

Variables

View Source
var ErrBackwards = errors.New("monotonic clock cannot move backwards")

Functions

This section is empty.

Types

type Clock

type Clock interface {
	NowNS() uint64
}

type Manual

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

Manual is a deterministic Scheduler for tests. Advancing it fires every timer whose deadline has passed, in deadline then scheduling order, with the clock already set to that timer's deadline so a callback that reads the time sees the moment it was scheduled for rather than the moment advancing ended.

func NewManual

func NewManual(startNS uint64) *Manual

func (*Manual) AdvanceNS

func (manual *Manual) AdvanceNS(durationNS uint64)

AdvanceNS moves the clock forward and fires everything due.

func (*Manual) AdvanceToNS

func (manual *Manual) AdvanceToNS(timestampNS uint64)

AdvanceToNS moves the clock to an absolute time and fires everything due.

func (*Manual) AfterFunc

func (manual *Manual) AfterFunc(delay time.Duration, callback func()) Timer

func (*Manual) NowNS

func (manual *Manual) NowNS() uint64

type Scheduler

type Scheduler interface {
	Clock
	AfterFunc(time.Duration, func()) Timer
}

Scheduler is a clock that can also schedule future work. Components that must act when nothing external happens - a playout horizon passing, a deadline expiring - take a Scheduler so tests can drive time explicitly rather than sleeping.

type System

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

func NewSystem

func NewSystem() *System

func (*System) AfterFunc

func (system *System) AfterFunc(delay time.Duration, callback func()) Timer

AfterFunc schedules callback on the wall clock.

func (*System) NowNS

func (system *System) NowNS() uint64

type Timer

type Timer interface {
	// Stop cancels the timer and reports whether it stopped it before it ran.
	Stop() bool
}

Timer is a scheduled callback that has not necessarily fired yet.

type Virtual

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

func NewVirtual

func NewVirtual(startNS uint64) *Virtual

func (*Virtual) AdvanceNS

func (clock *Virtual) AdvanceNS(durationNS uint64) (uint64, error)

func (*Virtual) AdvanceToNS

func (clock *Virtual) AdvanceToNS(timestampNS uint64) error

func (*Virtual) NowNS

func (clock *Virtual) NowNS() uint64

Jump to

Keyboard shortcuts

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