lib

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigOrDefault

func ConfigOrDefault[T comparable](conf, def T) T

ConfigOrDefault will return a value if it is non-zero (or empty), or a default value

func FmtFloat

func FmtFloat(f float64) string

FmtFloat is a custom float formatter that has a fixed precision of 2 decimal places with trailing zeros removed.

Types

type Event

type Event struct {
	Now    time.Time
	Ticker *Ticker
}

Event is sent from the per-ticker goroutine to a common channel when the ticker interval ticks over

func (*Event) Dispatch

func (e *Event) Dispatch()

Dispatch handles a tick event by invoking the callbacks registered on the ticker.

type Ticker

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

Ticker holds callbacks to be invoked at the specified period (e.g every 5 minutes)

func NewTicker

func NewTicker(tick, offset time.Duration) *Ticker

NewTicker creates and initialises a new ticker

func (*Ticker) AddCB

func (t *Ticker) AddCB(cb func(time.Time))

AddCB adds a callback to this ticker's callbacks

func (*Ticker) Start

func (t *Ticker) Start(ec chan<- Event)

Start initialises and starts the ticker by launching a goroutine that waits for the ticker interval, and then sends an event on the channel provided.

func (*Ticker) Tick

func (t *Ticker) Tick() time.Duration

Tick returns the interval duration for this ticker.

Jump to

Keyboard shortcuts

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