clock

package
v3.0.0-alpha-29 Latest Latest
Warning

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

Go to latest
Published: May 16, 2023 License: MIT Imports: 4 Imported by: 2

Documentation

Overview

Package clock provides an interface for clocks.

This is useful for testing code which checks does things based on time; it allows advancing the clock as needed by the tests, rather than needing to race with real time.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clock

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

A Clock can measure time.

var System Clock = systemClock{}

System reads the current time from the system clock.

type Manual

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

A Manual is a clock which is stopped, and only advances when its Advance method is called.

func NewManual

func NewManual(now time.Time) *Manual

Returns a new Manual clock, with the given initial time.

func (*Manual) Advance

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

Advance advances the clock forward by the given duration.

func (*Manual) NewTimer

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

func (*Manual) Now

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

Now returns the current time.

type Timer

type Timer interface {
	Chan() <-chan time.Time
	Reset(d time.Duration)
	Stop() bool
}

Jump to

Keyboard shortcuts

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