clocktest

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package clocktest provides deterministic clocks for tests that coordinate concurrent work around absolute deadlines.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manual

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

Manual is a concurrency-safe clock advanced explicitly by tests. Timer registration and the current time are checked under one lock, so a deadline cannot move from the future to the past between those operations.

func New

func New(now time.Time) *Manual

New returns a manual clock starting at now.

func (*Manual) Advance

func (c *Manual) Advance(by time.Duration)

Advance moves the clock forward and fires every timer whose deadline has elapsed.

func (*Manual) NewTimerAt

func (c *Manual) NewTimerAt(
	deadline time.Time,
) (<-chan time.Time, func() bool)

NewTimerAt registers a one-shot timer for deadline. The returned stop function reports whether it stopped an active timer.

func (*Manual) Now

func (c *Manual) Now() time.Time

Now returns the clock's current time.

func (*Manual) TimerCount

func (c *Manual) TimerCount() int

TimerCount reports the number of active timers.

Jump to

Keyboard shortcuts

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