relativetime

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 30, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clock

type Clock[T Time[T, D], D Duration, RT RTimer[T, D]] struct {
	// contains filtered or unexported fields
}

A clock implementation that tracks a reference clock with a configurable scaling factor. NOTE: composition with the reference clock would be such a nice feature here, to inherit all the methods of the reference clock. Maybe in a future version of Go... See `mocktime` package for an example of using embedding with instantiated generic types for a drop in replacement for a reference clock.

func NewClock

func NewClock[T Time[T, D], D Duration, RT RTimer[T, D]](ref RClock[T, D, RT], at T, scale float64) (c *Clock[T, D, RT])

func (*Clock[T, D, RT]) Active

func (c *Clock[T, D, RT]) Active() (active bool)

func (*Clock[T, D, RT]) After

func (c *Clock[T, D, RT]) After(d D) <-chan T

func (*Clock[T, D, RT]) AfterFunc

func (c *Clock[T, D, RT]) AfterFunc(d D, f func()) *Timer[T, D]

func (*Clock[T, D, RT]) NewTicker

func (c *Clock[T, D, RT]) NewTicker(d D) *Ticker[T, D]

func (*Clock[T, D, RT]) NewTimer

func (c *Clock[T, D, RT]) NewTimer(d D) *Timer[T, D]

func (*Clock[T, D, RT]) Now

func (c *Clock[T, D, RT]) Now() (now T)

func (*Clock[T, D, RT]) Scale

func (c *Clock[T, D, RT]) Scale() (scale float64)

func (*Clock[T, D, RT]) Seconds

func (c *Clock[T, D, RT]) Seconds(n float64) D

Use reference clock to implement Seconds method, to allow a relative clock to satisfy the reference clock interface itself.

func (*Clock[T, D, RT]) Set

func (c *Clock[T, D, RT]) Set(now T)

Set the local sync point with the current reference time to `now` If any timers are active, a value of `now` earlier than the previous setting may lead to undefined behavior.

func (*Clock[T, D, RT]) SetScale

func (c *Clock[T, D, RT]) SetScale(scale float64)

func (*Clock[T, D, RT]) Since

func (c *Clock[T, D, RT]) Since(t T) D

func (*Clock[T, D, RT]) Sleep

func (c *Clock[T, D, RT]) Sleep(d D)

func (*Clock[T, D, RT]) Start

func (c *Clock[T, D, RT]) Start()

Start() begins tracking the reference clock, if not already running. It is fine to call Start() on a clock that is already running.

func (*Clock[T, D, RT]) Step

func (c *Clock[T, D, RT]) Step(dt D)

Advance the local time forward by `dt`. If any timers are active, a negative value for dt may lead to undefined behavior.

func (*Clock[T, D, RT]) Stop

func (c *Clock[T, D, RT]) Stop()

Stop() stops tracking the reference clock, if currently running. It is fine to call Stop() on a clock that is not running.

func (*Clock[T, D, RT]) Tick

func (c *Clock[T, D, RT]) Tick(d D) <-chan T

func (*Clock[T, D, RT]) Until

func (c *Clock[T, D, RT]) Until(t T) D

type Duration

type Duration interface {
	Seconds() float64
}

Minimal API needed for a Duration implementation For example, `time.Duration` satisfies this interface

type RClock

type RClock[T Time[T, D], D Duration, TM RTimer[T, D]] interface {
	Now() T
	Seconds(float64) D
	NewTimer(D) TM
}

The minimal API needed to serve as a reference clock For example, `realtime.Clock` satisfies:

`RClock[time.Time, time.Duration, *realtime.Timer]`

type RTimer

type RTimer[T Time[T, D], D Duration] interface {
	C() <-chan T
	Reset(d D) bool
	Stop() bool
}

Minimal API needed for a reference Timer implementation For example, `*realtime.Timer` satisfies:

`RTimer[time.Time, time.Duration]`

type Ticker

type Ticker[T Time[T, D], D Duration] struct {
	// contains filtered or unexported fields
}

func (*Ticker[T, D]) C

func (t *Ticker[T, D]) C() <-chan T

func (*Ticker[T, D]) Reset

func (t *Ticker[T, D]) Reset(d D)

func (*Ticker[T, D]) Stop

func (t *Ticker[T, D]) Stop()

type Time

type Time[T any, D Duration] interface {
	Add(D) T
	Sub(T) D
	After(T) bool
	Before(T) bool
	Equal(T) bool
}

Minimal API needed for a Time implementation For example, `time.Time` satisfies:

`Time[time.Time, time.Duration]`

type Timer

type Timer[T Time[T, D], D Duration] struct {
	// contains filtered or unexported fields
}

func (*Timer[T, D]) C

func (t *Timer[T, D]) C() <-chan T

func (*Timer[T, D]) Reset

func (t *Timer[T, D]) Reset(d D) (active bool)

func (*Timer[T, D]) Stop

func (t *Timer[T, D]) Stop() (active bool)

Jump to

Keyboard shortcuts

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