feat: sig

This commit is contained in:
sujit
2025-03-29 19:06:28 +05:45
parent e8c503a488
commit 0205cf35ef
2 changed files with 28 additions and 5 deletions

7
mq.go
View File

@@ -125,16 +125,13 @@ type RateLimiter struct {
C chan struct{}
}
// Modified RateLimiter: use blocking send to avoid discarding tokens.
func NewRateLimiter(rate int, burst int) *RateLimiter {
rl := &RateLimiter{C: make(chan struct{}, burst)}
ticker := time.NewTicker(time.Second / time.Duration(rate))
go func() {
for range ticker.C {
select {
case rl.C <- struct{}{}:
default:
// bucket full; token discarded
}
rl.C <- struct{}{} // blocking send; tokens queue for deferred task processing
}
}()
return rl