fakeclock

package
v0.2.1 Latest Latest
Warning

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

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

Documentation

Overview

Package fakeclock is a deterministic clock for tests. Time moves only when a test calls Advance, which runs due timers synchronously in the caller's goroutine. Clock satisfies plugin.Clock without importing the plugin package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clock

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

Clock is a manually advanced clock.

func New

func New(start time.Time) *Clock

New returns a Clock that starts at start.

func (*Clock) Advance

func (c *Clock) Advance(d time.Duration)

Advance moves the clock forward by d, running every timer that becomes due, earliest first. A callback may schedule new timers, which run too when due.

func (*Clock) AfterFunc

func (c *Clock) AfterFunc(d time.Duration, f func()) interface{ Stop() bool }

AfterFunc schedules f to run when the clock has advanced by d.

func (*Clock) Now

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

Now returns the current fake time.

func (*Clock) Pending

func (c *Clock) Pending() int

Pending returns the number of timers that have neither fired nor been stopped.

Jump to

Keyboard shortcuts

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