mirror of
https://github.com/fiatjaf/khatru.git
synced 2025-03-17 21:32:55 +01:00
policies: shoehorn an iterator in a xsync map Range().
This commit is contained in:
parent
eb92c2aac5
commit
635e91f360
@ -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
|
||||
})
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user