https://github.com/mroth/jitter
:dancers: Go timers with random jitter
https://github.com/mroth/jitter
go golang random ticker timer
Last synced: 5 months ago
JSON representation
:dancers: Go timers with random jitter
- Host: GitHub
- URL: https://github.com/mroth/jitter
- Owner: mroth
- License: mit
- Created: 2020-04-09T22:00:47.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2025-01-24T15:51:55.000Z (8 months ago)
- Last Synced: 2025-04-06T19:11:18.448Z (6 months ago)
- Topics: go, golang, random, ticker, timer
- Language: Go
- Homepage:
- Size: 42 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# jitter
[](https://pkg.go.dev/github.com/mroth/jitter)
[](https://www.codefactor.io/repository/github/mroth/jitter)
[](https://github.com/mroth/jitter/actions)
[](https://codecov.io/gh/mroth/jitter)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](https://pkg.go.dev/github.com/mroth/jitter).
### Example Ticker
```go
// 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
}
```