mirror of
https://github.com/logos-messaging/logos-messaging-go.git
synced 2026-01-05 23:43:05 +00:00
chore: renaming
This commit is contained in:
parent
e42defcfef
commit
9385c1e2f9
@ -17,20 +17,20 @@ const RlnLimiterRefillInterval = 10 * time.Minute
|
|||||||
// RlnRateLimiter is used to rate limit the outgoing messages,
|
// RlnRateLimiter is used to rate limit the outgoing messages,
|
||||||
// The capacity and refillAfter comes from RLN contract configuration.
|
// The capacity and refillAfter comes from RLN contract configuration.
|
||||||
type RlnRateLimiter struct {
|
type RlnRateLimiter struct {
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
capacity int
|
capacity int
|
||||||
tokens int
|
tokens int
|
||||||
refillAfter time.Duration
|
refillInterval time.Duration
|
||||||
lastRefill time.Time
|
lastRefill time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRlnPublishRateLimiter creates a new rate limiter, starts with a full capacity bucket.
|
// NewRlnPublishRateLimiter creates a new rate limiter, starts with a full capacity bucket.
|
||||||
func NewRlnRateLimiter(capacity int, refillAfter time.Duration) *RlnRateLimiter {
|
func NewRlnRateLimiter(capacity int, refillInterval time.Duration) *RlnRateLimiter {
|
||||||
return &RlnRateLimiter{
|
return &RlnRateLimiter{
|
||||||
capacity: capacity,
|
capacity: capacity,
|
||||||
tokens: capacity, // Start with a full bucket
|
tokens: capacity, // Start with a full bucket
|
||||||
refillAfter: refillAfter,
|
refillInterval: refillInterval,
|
||||||
lastRefill: time.Now(),
|
lastRefill: time.Now(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ func (rl *RlnRateLimiter) Allow() bool {
|
|||||||
|
|
||||||
// Refill tokens if the refill interval has passed
|
// Refill tokens if the refill interval has passed
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
if now.Sub(rl.lastRefill) >= rl.refillAfter {
|
if now.Sub(rl.lastRefill) >= rl.refillInterval {
|
||||||
rl.tokens = rl.capacity // Refill the bucket
|
rl.tokens = rl.capacity // Refill the bucket
|
||||||
rl.lastRefill = now
|
rl.lastRefill = now
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user