Skip to content

mroth/jitter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

de46d42 Â· Jan 24, 2025

History

48 Commits
Jan 24, 2025
Jun 10, 2022
Apr 9, 2020
Jun 19, 2022
Jan 22, 2025
Jun 19, 2022
Jul 24, 2020
Jun 19, 2022
Jun 19, 2022
Jun 10, 2022
Jul 25, 2020

Repository files navigation

jitter

PkgGoDev CodeFactor Build Status codecov

A simple Go library providing functionality for generating durations and tickers that deviate from true periodicity within specified bounds.

Most notably, contains a nearly API compatible version of time.Ticker with definable jitter.

Usage

For usage details, see the Go documentation.

Example Ticker

// ticker with base duration of 1 second and 0.5 scaling factor
ticker := jitter.NewTicker(time.Second, 0.5)
defer ticker.Stop()

prev := time.Now()
for {
    t := <-ticker.C // time elapsed random in range (0.5s, 1.5s)
    fmt.Println("Time elapsed since last tick: ", t.Sub(prev))
    prev = t
}