go-ipfs-delay – github.com/ipfs/go-ipfs-delay Index | Files

package delay

import "github.com/ipfs/go-ipfs-delay"

Index

Types

type D

type D interface {
	Set(time.Duration) time.Duration
	Wait()
	NextWaitTime() time.Duration
	Get() time.Duration
}

D (Delay) makes it easy to add (threadsafe) configurable delays to other objects.

func Delay

func Delay(t time.Duration, generator Generator) D

Delay generates a generic delay form a t, a sleeper, and a generator

func Fixed

func Fixed(t time.Duration) D

Fixed returns a delay with fixed latency

func VariableNormal

func VariableNormal(t, std time.Duration, rng *rand.Rand) D

VariableNormal is a delay following a normal distribution Notice that to implement the D interface Set can only change the mean delay the standard deviation is set only at initialization

func VariableUniform

func VariableUniform(t, d time.Duration, rng *rand.Rand) D

VariableUniform is a delay following a uniform distribution Notice that to implement the D interface Set can only change the minimum delay the delta is set only at initialization

type Generator

type Generator interface {
	NextWaitTime(time.Duration) time.Duration
}

Generator provides an interface for generating wait times

func FixedGenerator

func FixedGenerator() Generator

FixedGenerator returns a delay with fixed latency

func VariableNormalGenerator

func VariableNormalGenerator(std time.Duration, rng *rand.Rand) Generator

VariableNormalGenerator makes delays that following a normal distribution

func VariableUniformGenerator

func VariableUniformGenerator(d time.Duration, rng *rand.Rand) Generator

VariableUniformGenerator generates delays following a uniform distribution

Source Files

delay.go generator.go

Version
v0.0.1 (latest)
Published
Feb 28, 2019
Platform
linux/amd64
Imports
3 packages
Last checked
2 months ago

Tools for package owners.