utils

package
v1.8.4 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clock

type Clock interface {
	Now() time.Time
	Increment(int64, int64) time.Time
}

Clock provides an interface to implement method for getting current time.

type DefaultClock

type DefaultClock struct{}

DefaultClock is an implementation of Clock interface.

func (*DefaultClock) Increment

func (t *DefaultClock) Increment(_, _ int64) time.Time

This method returns the current time but can be used to provide different implementation

func (*DefaultClock) Now

func (t *DefaultClock) Now() time.Time

Now returns current time.

type DefaultRand

type DefaultRand struct{}

DefaultRand is an implementation of Rand interface. It is safe for concurrent use by multiple goroutines.

func (*DefaultRand) Float64

func (r *DefaultRand) Float64() float64

Float64 returns, as a float64, a pseudo-random number in [0.0,1.0) from the default Source.

func (*DefaultRand) Int63n

func (r *DefaultRand) Int63n(n int64) int64

Int63n returns, as an int64, a non-negative pseudo-random number in [0,n) from the default Source.

func (*DefaultRand) Intn

func (r *DefaultRand) Intn(n int) int

Intn returns, as an int, a non-negative pseudo-random number in [0,n) from the default Source.

type MockClock

type MockClock struct {
	NowTime  int64
	NowNanos int64
}

MockClock is a struct to record current time.

func (*MockClock) Increment

func (c *MockClock) Increment(s int64, ns int64) time.Time

Increment is a method to increase current time.

func (*MockClock) Now

func (c *MockClock) Now() time.Time

Now function returns NowTime value.

type MockRand

type MockRand struct {
	F64   float64
	Int   int
	Int64 int64
}

MockRand is an implementation of Rand interface.

func (*MockRand) Float64

func (r *MockRand) Float64() float64

Float64 returns value of F64.

func (*MockRand) Int63n

func (r *MockRand) Int63n(n int64) int64

Int63n returns value of Int64.

func (*MockRand) Intn

func (r *MockRand) Intn(n int) int

Intn returns value of Int.

type Rand

type Rand interface {
	Int63n(n int64) int64
	Intn(n int) int
	Float64() float64
}

Rand is an interface for a set of methods that return random value.

type Timer

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

Timer is the same as time.Timer except that it has jitters. A Timer must be created with NewTimer.

func NewTimer

func NewTimer(d, jitter time.Duration) *Timer

NewTimer creates a new Timer that will send the current time on its channel.

func (*Timer) C

func (j *Timer) C() <-chan time.Time

C is channel.

func (*Timer) Reset

func (j *Timer) Reset()

Reset resets the timer. Reset should be invoked only on stopped or expired timers with drained channels.

Jump to

Keyboard shortcuts

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