* 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
31 lines
387 B
Go
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{}
|