Documentation
¶
Index ¶
- type Clock
- func (c *Clock[T, D, RT]) Active() (active bool)
- func (c *Clock[T, D, RT]) After(d D) <-chan T
- func (c *Clock[T, D, RT]) AfterFunc(d D, f func()) *Timer[T, D]
- func (c *Clock[T, D, RT]) NewTicker(d D) *Ticker[T, D]
- func (c *Clock[T, D, RT]) NewTimer(d D) *Timer[T, D]
- func (c *Clock[T, D, RT]) Now() (now T)
- func (c *Clock[T, D, RT]) Scale() (scale float64)
- func (c *Clock[T, D, RT]) Seconds(n float64) D
- func (c *Clock[T, D, RT]) Set(now T)
- func (c *Clock[T, D, RT]) SetScale(scale float64)
- func (c *Clock[T, D, RT]) Since(t T) D
- func (c *Clock[T, D, RT]) Sleep(d D)
- func (c *Clock[T, D, RT]) Start()
- func (c *Clock[T, D, RT]) Step(dt D)
- func (c *Clock[T, D, RT]) Stop()
- func (c *Clock[T, D, RT]) Tick(d D) <-chan T
- func (c *Clock[T, D, RT]) Until(t T) D
- type Duration
- type RClock
- type RTimer
- type Ticker
- type Time
- type Timer
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 (*Clock[T, D, RT]) Seconds ¶
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]) 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.
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 ¶
Minimal API needed for a reference Timer implementation For example, `*realtime.Timer` satisfies:
`RTimer[time.Time, time.Duration]`
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]`