diff options
Diffstat (limited to 'common/maps/cache.go')
-rw-r--r-- | common/maps/cache.go | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/common/maps/cache.go b/common/maps/cache.go index cdc31a684..72c07e7ca 100644 --- a/common/maps/cache.go +++ b/common/maps/cache.go @@ -113,11 +113,14 @@ func (c *Cache[K, T]) set(key K, value T) { } // ForEeach calls the given function for each key/value pair in the cache. -func (c *Cache[K, T]) ForEeach(f func(K, T)) { +// If the function returns false, the iteration stops. +func (c *Cache[K, T]) ForEeach(f func(K, T) bool) { c.RLock() defer c.RUnlock() for k, v := range c.m { - f(k, v) + if !f(k, v) { + return + } } } |