timers

package
v0.0.0-...-15eb78e Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2022 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package timers provides a Clock abstraction useful for simulating timeouts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clock

type Clock interface {
	// Zero returns a reset Clock. TimeoutAt channels will use the point
	// at which Zero was called as their reference point.
	Zero() Clock

	// TimeoutAt returns a channel that fires delta time after Zero was called.
	// 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) <-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, error)
}

Clock provides timeout events which fire at some point after a point in time.

func MakeFrozenClock

func MakeFrozenClock() Clock

MakeFrozenClock creates a new frozen clock.

func MakeMonotonicClock

func MakeMonotonicClock(zero time.Time) Clock

MakeMonotonicClock creates a new monotonic clock with a given zero point.

type Frozen

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

Frozen is a dummy frozen clock that never fires.

func (*Frozen) Decode

func (m *Frozen) Decode([]byte) (Clock, error)

Decode implements Clock.Decode.

func (*Frozen) Encode

func (m *Frozen) Encode() []byte

Encode implements Clock.Encode.

func (*Frozen) String

func (m *Frozen) String() string

func (*Frozen) TimeoutAt

func (m *Frozen) TimeoutAt(delta time.Duration) <-chan time.Time

TimeoutAt returns a channel that will signal when the duration has elapsed.

func (*Frozen) Zero

func (m *Frozen) Zero() Clock

Zero returns a new Clock reset to the current time.

type Monotonic

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

Monotonic uses the system's monotonic clock to emit timeouts.

func (*Monotonic) Decode

func (m *Monotonic) Decode(data []byte) (Clock, error)

Decode implements Clock.Decode.

func (*Monotonic) Encode

func (m *Monotonic) Encode() []byte

Encode implements Clock.Encode.

func (*Monotonic) String

func (m *Monotonic) String() string

func (*Monotonic) TimeoutAt

func (m *Monotonic) TimeoutAt(delta time.Duration) <-chan time.Time

TimeoutAt returns a channel that will signal when the duration has elapsed.

func (*Monotonic) Zero

func (m *Monotonic) Zero() Clock

Zero returns a new Clock reset to the current time.

Jump to

Keyboard shortcuts

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