Help us shape the future of Go! Take the 2026 Go Developer Survey

clock

package
v1.15.5 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: Apache-2.0 Imports: 4 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clock

type Clock clock.Clock

Clock is a clock

type Mock

type Mock struct {
	*clock.Mock
	// contains filtered or unexported fields
}

Mock is a mock clock that can be precisely controlled

func NewMock

func NewMock(t testing.TB) *Mock

NewMock creates a mock clock which can be precisely controlled

func NewMockAt added in v1.6.0

func NewMockAt(t testing.TB, now time.Time) *Mock

NewMockAt creates a mock clock which can be precisely controlled at a specific time.

func (*Mock) After

func (m *Mock) After(d time.Duration) <-chan time.Time

After waits for the duration to elapse and then sends the current time on the returned channel.

func (*Mock) SetAfterHook added in v1.8.3

func (m *Mock) SetAfterHook(h func(time.Duration) <-chan time.Time)

func (*Mock) Sleep

func (m *Mock) Sleep(d time.Duration)

Sleep pauses the current goroutine for at least the duration d

func (*Mock) SleepCh added in v1.15.2

func (m *Mock) SleepCh() <-chan time.Duration

SleepCh returns the channel that Sleep notifies when a sleep begins, carrying the sleep duration. The notification is a non-blocking send on a buffered channel, so it can be dropped if a previous one has not been drained. Drive a Sleep-based retry loop by receiving each notification and advancing the clock by its duration before the next Sleep can begin: that keeps at most one sleep outstanding (so nothing is dropped) and avoids coupling to the number of sleeps.

func (*Mock) Ticker

func (m *Mock) Ticker(d time.Duration) *clock.Ticker

Ticker returns a new Ticker containing a channel that will send the time with a period specified by the duration argument.

func (*Mock) Timer

func (m *Mock) Timer(d time.Duration) *clock.Timer

Timer creates a new Timer containing a channel that will send the time with a period specified by the duration argument.

func (*Mock) TimerCh

func (m *Mock) TimerCh() <-chan time.Duration

func (*Mock) WaitForAfter

func (m *Mock) WaitForAfter(timeout time.Duration, format string, args ...any)

WaitForAfter waits up to the specified timeout for After to be called on the clock.

func (*Mock) WaitForAfterCh added in v1.4.2

func (m *Mock) WaitForAfterCh() <-chan time.Duration

func (*Mock) WaitForSleep

func (m *Mock) WaitForSleep(timeout time.Duration, format string, args ...any)

WaitForSleep waits up to the specified timeout for a sleep to begin using the clock.

func (*Mock) WaitForTicker

func (m *Mock) WaitForTicker(timeout time.Duration, format string, args ...any)

WaitForTicker waits up to the specified timeout for a Ticker to be created from the clock.

func (*Mock) WaitForTickerMulti

func (m *Mock) WaitForTickerMulti(timeout time.Duration, count int32, format string, args ...any)

func (*Mock) WaitForTimer

func (m *Mock) WaitForTimer(timeout time.Duration, format string, args ...any)

WaitForTimer waits up to the specified timeout for Timer to be called on the clock.

Jump to

Keyboard shortcuts

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