timex

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package timex provides a Ticker abstraction with a fake implementation for deterministic, clock-injectable tests of periodic logic.

Index

Constants

This section is empty.

Variables

View Source
var ErrTimeout = errors.New("timex: wait timeout")

ErrTimeout is returned by FakeTicker.Wait when the deadline elapses first.

Functions

This section is empty.

Types

type FakeTicker

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

FakeTicker is a manually-driven Ticker for tests.

func NewFakeTicker

func NewFakeTicker() *FakeTicker

NewFakeTicker returns a FakeTicker that must be advanced with Tick.

func (*FakeTicker) Chan

func (ft *FakeTicker) Chan() <-chan time.Time

Chan returns the tick channel.

func (*FakeTicker) Done

func (ft *FakeTicker) Done() <-chan struct{}

Done returns a channel closed when Stop is called.

func (*FakeTicker) Stop

func (ft *FakeTicker) Stop()

Stop closes the Done channel; it is safe to call multiple times.

func (*FakeTicker) Tick

func (ft *FakeTicker) Tick()

Tick emits a single tick.

func (*FakeTicker) Wait

func (ft *FakeTicker) Wait(d time.Duration) error

Wait blocks until Stop is called or the duration elapses, whichever first.

type Ticker

type Ticker interface {
	// Chan returns the tick channel.
	Chan() <-chan time.Time
	// Stop stops the ticker.
	Stop()
}

Ticker emits periodic ticks.

func NewTicker

func NewTicker(d time.Duration) Ticker

NewTicker returns a real Ticker with the given interval.

Jump to

Keyboard shortcuts

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