utils

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

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
	NewTimer(d time.Duration) Timer
}

Clock allows time to be controlled in tests.

type FakeClock

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

FakeClock is a controllable clock for tests. - Now() returns the current fake time. - NewTimer(d) creates a manual timer that fires when Advance moves time >= now+d. FakeClock is a controllable clock for tests. It also allows observing timer creation to write deterministic "it blocks" assertions without relying on goroutine scheduling luck.

func NewFakeClock

func NewFakeClock(start time.Time) *FakeClock

func (*FakeClock) Advance

func (fc *FakeClock) Advance(d time.Duration)

Advance moves time forward and fires any timers that are due.

func (*FakeClock) NewTimer

func (fc *FakeClock) NewTimer(d time.Duration) Timer

func (*FakeClock) Now

func (fc *FakeClock) Now() time.Time

func (*FakeClock) TimersCreated

func (fc *FakeClock) TimersCreated() int

TimersCreated returns how many timers have been created so far.

func (*FakeClock) WaitForTimersCreated

func (fc *FakeClock) WaitForTimersCreated(n int)

WaitForTimersCreated blocks until at least n timers have been created.

type ManualTimer

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

func (*ManualTimer) C

func (mt *ManualTimer) C() <-chan time.Time

func (*ManualTimer) Stop

func (mt *ManualTimer) Stop() bool

type RealClock

type RealClock struct{}

func (RealClock) NewTimer

func (RealClock) NewTimer(d time.Duration) Timer

func (RealClock) Now

func (RealClock) Now() time.Time

type RealTimer

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

func (RealTimer) C

func (rt RealTimer) C() <-chan time.Time

func (RealTimer) Stop

func (rt RealTimer) Stop() bool

type Timer

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

Timer abstracts time.Timer for testability.

Jump to

Keyboard shortcuts

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