clock

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package clock supplies injectable clocks and cancellable waiting.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Wait

func Wait(ctx context.Context, c Clock, d time.Duration) error

Wait waits using an injected clock, stopping on context cancellation.

Types

type Clock

type Clock interface {
	Now() time.Time
	NewTimer(time.Duration) Timer
}

Clock abstracts current time and owned timers.

type Manual

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

Manual advances only when Advance is called; timers have buffered channels.

func NewManual

func NewManual(now time.Time) *Manual

NewManual creates a deterministic manual clock.

func (*Manual) Advance

func (m *Manual) Advance(d time.Duration)

Advance advances the manual clock and fires due timers.

func (*Manual) NewTimer

func (m *Manual) NewTimer(d time.Duration) Timer

NewTimer creates an owned timer.

func (*Manual) Now

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

Now returns the current UTC time.

type Real

type Real struct{}

Real uses the system UTC clock and timers.

func (Real) NewTimer

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

NewTimer creates an owned timer.

func (Real) Now

func (Real) Now() time.Time

Now returns the current UTC time.

type Timer

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

Timer exposes timer delivery and cancellation.

Jump to

Keyboard shortcuts

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