delayed

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package delayed wraps a datastore allowing to artificially delay all operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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 Delayed

type Delayed struct {
	// contains filtered or unexported fields
}

Delayed is an adapter that delays operations on the inner datastore.

func New

func New(ds ds.Datastore, delay D) *Delayed

New returns a new delayed datastore.

func (*Delayed) Batch

func (dds *Delayed) Batch(ctx context.Context) (ds.Batch, error)

Batch implements the ds.Batching interface.

func (*Delayed) Close

func (dds *Delayed) Close() error

Close closes the inner datastore (if it implements the io.Closer interface).

func (*Delayed) Delete

func (dds *Delayed) Delete(ctx context.Context, key ds.Key) (err error)

Delete implements the ds.Datastore interface.

func (*Delayed) DiskUsage

func (dds *Delayed) DiskUsage(ctx context.Context) (uint64, error)

DiskUsage implements the ds.PersistentDatastore interface.

func (*Delayed) Get

func (dds *Delayed) Get(ctx context.Context, key ds.Key) (value []byte, err error)

Get implements the ds.Datastore interface.

func (*Delayed) GetSize

func (dds *Delayed) GetSize(ctx context.Context, key ds.Key) (size int, err error)

GetSize implements the ds.Datastore interface.

func (*Delayed) Has

func (dds *Delayed) Has(ctx context.Context, key ds.Key) (exists bool, err error)

Has implements the ds.Datastore interface.

func (*Delayed) Put

func (dds *Delayed) Put(ctx context.Context, key ds.Key, value []byte) (err error)

Put implements the ds.Datastore interface.

func (*Delayed) Query

func (dds *Delayed) Query(ctx context.Context, q dsq.Query) (dsq.Results, error)

Query implements the ds.Datastore interface.

func (*Delayed) Sync

func (dds *Delayed) Sync(ctx context.Context, prefix ds.Key) error

Sync implements Datastore.Sync

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

Jump to

Keyboard shortcuts

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