Range iterates the pool similarly to how sync.Map.Range() does: it calls f for every key in the pool, and if f returns false, iteration is stopped. Ranging does not affect usage counts. This method is somewhat naive and acquires a read lock on the entire pool during iteration, so do your best to ma
(f func(key, value any) bool)
| 147 | // entire pool during iteration, so do your best to make f() really |
| 148 | // fast, m'kay? |
| 149 | func (up *UsagePool) Range(f func(key, value any) bool) { |
| 150 | up.RLock() |
| 151 | defer up.RUnlock() |
| 152 | for key, upv := range up.pool { |
| 153 | upv.RLock() |
| 154 | if upv.err != nil { |
| 155 | upv.RUnlock() |
| 156 | continue |
| 157 | } |
| 158 | val := upv.value |
| 159 | upv.RUnlock() |
| 160 | if !f(key, val) { |
| 161 | break |
| 162 | } |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | // Delete decrements the usage count for key and removes the |
| 167 | // value from the underlying map if the usage is 0. It returns |
no outgoing calls
no test coverage detected