clock

package
v0.175.0-rc.526 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package clock is beekeeper's time: Now, Since, Until, After, Sleep, NewTimer, NewTicker and AfterFunc, in place of the time package's, and WithTimeout in place of context.WithTimeout.

A release build uses the system clock and nothing else: every function is the time package's own, and nothing reads the environment.

A scenario build (go build -tags scenario, docs/scenarios.md) reads Env. When it names a socket, every process of the scenario reads the scenario world's time from it: the system clock moved by the world's offset. The world's advance step moves that offset forward and wakes, in every process, the timers, tickers and sleeps then due, so an hour of loop passes takes seconds. Without Env a scenario build uses the system clock too.

The core flows use this package instead of the time package's clock functions; TestMigratedPackagesUseTheClock lists them and fails when one of them calls the time package's clock again.

Index

Constants

View Source
const Env = "BEEKEEPER_SCENARIO_CLOCK"

Env names the scenario world's clock socket to a scenario build. A release build never reads it.

View Source
const Scenario = false

Scenario says this build reads a scenario world's clock (Env); a release build never does.

Variables

This section is empty.

Functions

func After

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

After receives the time once d has passed.

func Now

func Now() time.Time

Now is the current time.

func Since

func Since(t time.Time) time.Duration

Since is the time elapsed since t.

func Sleep

func Sleep(d time.Duration)

Sleep pauses for at least d.

func Until

func Until(t time.Time) time.Duration

Until is the duration until t.

func WithTimeout

func WithTimeout(parent context.Context, d time.Duration) (context.Context, context.CancelFunc)

WithTimeout is context.WithTimeout on the clock: the context ends once d has passed on it, the world's time in a scenario. Deadline and Err answer as context.WithTimeout's do: Err is context.DeadlineExceeded once d has passed.

Types

type Ticker

type Ticker struct {
	C <-chan time.Time
	// contains filtered or unexported fields
}

Ticker is time.Ticker on the clock: C receives the time every period, dropping ticks a slow receiver misses.

func NewTicker

func NewTicker(d time.Duration) *Ticker

NewTicker is a Ticker of period d, which must be positive.

func (*Ticker) Reset

func (t *Ticker) Reset(d time.Duration)

Reset stops the ticker and restarts it with period d.

func (*Ticker) Stop

func (t *Ticker) Stop()

Stop stops the ticker; C receives no tick after it.

type Timer

type Timer struct {
	C <-chan time.Time
	// contains filtered or unexported fields
}

Timer is time.Timer on the clock: C receives the time once it fires, nil for one of AfterFunc.

func AfterFunc

func AfterFunc(d time.Duration, f func()) *Timer

AfterFunc calls f in its own goroutine once d has passed.

func NewTimer

func NewTimer(d time.Duration) *Timer

NewTimer is a Timer that fires after d.

func (*Timer) Reset

func (t *Timer) Reset(d time.Duration) bool

Reset makes the timer fire after d; false when it had fired or been stopped already.

func (*Timer) Stop

func (t *Timer) Stop() bool

Stop stops the timer; false when it had fired or been stopped already. As with time.Timer since Go 1.23, no stale time is received after it.

Jump to

Keyboard shortcuts

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