mirror of
https://github.com/aljazceru/khatru.git
synced 2026-01-14 10:54:20 +01:00
policies: shoehorn an iterator in a xsync map Range().
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package policies
|
||||
|
||||
import (
|
||||
"iter"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
@@ -18,13 +19,12 @@ func startRateLimitSystem[K comparable](
|
||||
go func() {
|
||||
for {
|
||||
time.Sleep(interval)
|
||||
negativeBuckets.Range(func(key K, bucket *atomic.Int32) bool {
|
||||
for key, bucket := range iter.Seq2[K, *atomic.Int32](negativeBuckets.Range) {
|
||||
newv := bucket.Add(int32(-tokensPerInterval))
|
||||
if newv <= 0 {
|
||||
negativeBuckets.Delete(key)
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user