clock

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2023 License: MIT Imports: 0 Imported by: 0

README

clock

The clock package duplicates much of the functionality of time from the standard library, while allowing for greater control over the flow of time for use in testing and simulations. Each clock instance may track its own flow of time (using its own definitions of Time or Duration as necessary), while appropriately triggering Timers and Tickers created with them. These may be useful for mocking the time package in test code as well as working with simulation timers while retaining the familiar API of the time package.

In general, clocks provided by these packages should behave monotonically (unless explicitly set or stepped backwards) and should also provide a thread-safe public interface. There are several implementations supplied in subpackages below.

The design of this package is mostly complete, though there may still be some bugs to work out or minor API changes before a stable release.

clock/realtime

A thin wrapper around the time package. One important caveat is that Timers and Tickers provide access to their channel via a C() method rather than a field of the same name. This was decided to permit easier specification of interfaces.

clock/steppedtime

A basic clock implementation using a simple time representation that starts at zero and counts upwards. It advances only when explicitly stepped.

clock/relativetime

A clock that can be set to track another clock as a reference with a specified offset and scaling factor. It may start, stop, or adjust any tracking parameters at runtime, with timers created on it behaving appropriately. It is defined with a generic interface so that it may be used with clocks that use various implementations of time or duration values.

clock/mocktime

Uses relativetime and realtime to implement a drop in replacement for a realtime clock with all the additional control of a relative clock. It also provides package-level functions to match the API of the standard library's time package, for mocking purposes. Note that the caveats for Timers and Tickers mentioned for realtime clocks above apply here as well.

Documentation

Overview

Package clock offers a more object-oriented interface to the time package from the standard library in the form of "Clocks", allowing greater control over the flow of time. Clocks also enable isolation between individually configurable instances, analogous to [rand]'s alternative interface via instances of [rand.Rand]. Each Clock instance may track its own flow of time, appropriately triggering Timers and Tickers created with them. There are several implementations supplied by subpackages.

Directories

Path Synopsis
Package mocktime provides a drop in replacement for time that starts at a fixed epoch and may be controlled as a relative clock.
Package mocktime provides a drop in replacement for time that starts at a fixed epoch and may be controlled as a relative clock.
Package realtime provides a thin wrapper around the time package.
Package realtime provides a thin wrapper around the time package.
Package relativetime provides a clock that can be set to track a reference clock with a specified offset and scaling factor, and may start, stop, or adjust tracking parameters while running.
Package relativetime provides a clock that can be set to track a reference clock with a specified offset and scaling factor, and may start, stop, or adjust tracking parameters while running.
Package steppedtime provides a simple clock and time implementation starting at zero and counting upwards.
Package steppedtime provides a simple clock and time implementation starting at zero and counting upwards.

Jump to

Keyboard shortcuts

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