clock

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend interface {
	Now() time.Time
	Since(t time.Time) time.Duration
	NewTicker(d time.Duration) Ticker
	NewTimer(d time.Duration) Timer
}

Backend provides primitive clock functions.

type Clock

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

Clock implements a clock. The zero value is valid and uses the real time functions.

func New

func New(backend Backend) Clock

New returns a clock that uses the given backend.

func (Clock) NewLazyTimer

func (c Clock) NewLazyTimer() Timer

func (Clock) NewTicker

func (c Clock) NewTicker(d time.Duration) Ticker

NewTicker provides functionality equivalent to time.NewTicker. It is safe to call on a zero value.

func (Clock) NewTimer

func (c Clock) NewTimer(d time.Duration) Timer

NewTimer provides functionality equivalent to time.NewTimer. It is safe to call on a zero value.

func (Clock) Now

func (c Clock) Now() time.Time

Now provides functionality equivalent to time.Now. It is safe to call on a zero value.

func (Clock) Since

func (c Clock) Since(t time.Time) time.Duration

Since provides functionality equivalent to time.Since. It is safe to call on a zero value.

func (Clock) Sleep

func (c Clock) Sleep(ctx context.Context, d time.Duration) bool

Sleep is a convenience function that provides functionality equivalent to time.Sleep, except that it respects context cancellation. True is returned if the timer expired or false if the context was done.

type Ticker

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

Ticker provides functionality equivalent to time.Ticker.

type Timer

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

Timer provides functionality equivalent to time.Timer.

Jump to

Keyboard shortcuts

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