repeat

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Every

func Every(d time.Duration, fn func(), jitter ...float64) func()

Every runs fn in a goroutine every d duration until the returned stop function is called. The first invocation happens immediately so callers don't have to wait one full period for their initialization tick.

An optional jitter fraction in [0, 1] spreads tick timing uniformly in [d*(1-jitter), d*(1+jitter)]. Use it to avoid thundering herds when many instances start the same recurring task at the same time (e.g. a fleet rolling out simultaneously, all nodes hitting the same database every 10s in lockstep). Jitter applies to both the initial delay and every subsequent tick. Pass 0 (or omit entirely) for fixed-cadence behavior.

Values outside [0, 1] are clamped: negative becomes 0, anything above 1 becomes 1. Beyond 1.0 the lower bound on the jittered duration goes non-positive, which is meaningless for a periodic timer.

func EveryClock

func EveryClock(c clock.Clock, d time.Duration, fn func(), jitter ...float64) func()

EveryClock is like Every but drives fixed-cadence schedules from the supplied clock.Clock. Tests can pass a clock.TestClock so simulated time advances drive the firing schedule instead of racing real wall time.

Types

This section is empty.

Jump to

Keyboard shortcuts

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