package jitter

import "github.com/Rican7/retry/jitter"

Package jitter provides methods of transforming durations.

Copyright © 2016 Trevor N. Suarez (Rican7)

Index

Types

type Transformation

type Transformation func(duration time.Duration) time.Duration

Transformation defines a function that calculates a time.Duration based on the given duration.

func Deviation

func Deviation(generator *rand.Rand, factor float64) Transformation

Deviation creates a Transformation that transforms a duration into a result duration that deviates from the input randomly by a given factor.

The given generator is what is used to determine the random transformation. If a nil generator is passed, a default one will be provided.

Inspired by https://developers.google.com/api-client-library/java/google-http-java-client/backoff

func Equal

func Equal(generator *rand.Rand) Transformation

Equal creates a Transformation that transforms a duration into a result duration in [n/2, n) randomly, where n is the given duration.

The given generator is what is used to determine the random transformation. If a nil generator is passed, a default one will be provided.

Inspired by https://www.awsarchitectureblog.com/2015/03/backoff.html

func Full

func Full(generator *rand.Rand) Transformation

Full creates a Transformation that transforms a duration into a result duration in [0, n) randomly, where n is the given duration.

The given generator is what is used to determine the random transformation. If a nil generator is passed, a default one will be provided.

Inspired by https://www.awsarchitectureblog.com/2015/03/backoff.html

func NormalDistribution

func NormalDistribution(generator *rand.Rand, standardDeviation float64) Transformation

NormalDistribution creates a Transformation that transforms a duration into a result duration based on a normal distribution of the input and the given standard deviation.

The given generator is what is used to determine the random transformation. If a nil generator is passed, a default one will be provided.

Source Files

jitter.go

Version
v0.3.1 (latest)
Published
Aug 12, 2021
Platform
linux/amd64
Imports
3 packages
Last checked
1 day ago

Tools for package owners.