Documentation
¶
Overview ¶
Package timers provides a Clock abstraction useful for simulating timeouts.
Index ¶
- type Clock
- type Frozen
- func (m *Frozen[TimeoutType]) Decode([]byte) (Clock[TimeoutType], error)
- func (m *Frozen[TimeoutType]) Encode() []byte
- func (m *Frozen[TimeoutType]) Since() time.Duration
- func (m *Frozen[TimeoutType]) String() string
- func (m *Frozen[TimeoutType]) TimeoutAt(delta time.Duration, timeoutType TimeoutType) <-chan time.Time
- func (m *Frozen[TimeoutType]) Zero() Clock[TimeoutType]
- type Monotonic
- func (m *Monotonic[TimeoutType]) Decode(data []byte) (Clock[TimeoutType], error)
- func (m *Monotonic[TimeoutType]) Encode() []byte
- func (m *Monotonic[TimeoutType]) Since() time.Duration
- func (m *Monotonic[TimeoutType]) String() string
- func (m *Monotonic[TimeoutType]) TimeoutAt(delta time.Duration, timeoutType TimeoutType) <-chan time.Time
- func (m *Monotonic[TimeoutType]) Zero() Clock[TimeoutType]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Clock ¶
type Clock[TimeoutType comparable] interface { // Zero returns a reset Clock. TimeoutAt channels will use the point // at which Zero was called as their reference point. Zero() Clock[TimeoutType] // Since returns the time spent between the last time the clock was zeroed out and the current // wall clock time. Since() time.Duration // TimeoutAt returns a channel that fires delta time after Zero was called. // timeoutType is specifies the reason for this timeout. If there are two // timeouts of the same type at the same time, then only one of them fires. // If delta has already passed, it returns a closed channel. // // TimeoutAt must be called after Zero; otherwise, the channel's behavior is // undefined. TimeoutAt(delta time.Duration, timeoutType TimeoutType) <-chan time.Time // Encode serializes the Clock into a byte slice. Encode() []byte // Decode deserializes the Clock from a byte slice. // A Clock which has been Decoded from an Encoded Clock should produce // the same timeouts as the original Clock. Decode([]byte) (Clock[TimeoutType], error) }
Clock provides timeout events which fire at some point after a point in time.
func MakeFrozenClock ¶
func MakeFrozenClock[TimeoutType comparable]() Clock[TimeoutType]
MakeFrozenClock creates a new frozen clock.
func MakeMonotonicClock ¶
func MakeMonotonicClock[TimeoutType comparable](zero time.Time) Clock[TimeoutType]
MakeMonotonicClock creates a new monotonic clock with a given zero point.
type Frozen ¶
type Frozen[TimeoutType comparable] struct { // contains filtered or unexported fields }
Frozen is a dummy frozen clock that never fires.
type Monotonic ¶
type Monotonic[TimeoutType comparable] struct { // contains filtered or unexported fields }
Monotonic uses the system's monotonic clock to emit timeouts.
func (*Monotonic[TimeoutType]) Since ¶
Since returns the time that has passed between the time the clock was last zeroed out and now
Click to show internal directories.
Click to hide internal directories.