Files
protocol/utils/clock.go
Lukas Herman c69c1b0580 add Clock interface and LeakyBucket (#675)
* add Clock interface and LeakyBucket

* add SimulatedClock

* removed self reference and format

* renamed t to lb

* replaced sync/atomic with uber/atomic

* add source to the license comment

* favor value over pointer receiver for SystemClock

* use atomic.Int value

* use mutex based instead

* add source

* update comments and hide mutex

* add SetRateLimitOnTheFly

* fix: source in rate_test

* skip unstable slack tests on Github
2024-04-09 11:32:35 -04:00

31 lines
387 B
Go

package utils
import (
"time"
"github.com/benbjohnson/clock"
)
type Clock interface {
Now() time.Time
Sleep(time.Duration)
}
type SystemClock struct{}
var _ Clock = &SystemClock{}
func (SystemClock) Now() time.Time {
return time.Now()
}
func (SystemClock) Sleep(d time.Duration) {
time.Sleep(d)
}
type SimulatedClock struct {
clock.Mock
}
var _ Clock = &SimulatedClock{}