References returns the number of references (count of usages) to a key in the pool, and true if the key exists, or false otherwise.
(key any)
| 199 | // References returns the number of references (count of usages) to a |
| 200 | // key in the pool, and true if the key exists, or false otherwise. |
| 201 | func (up *UsagePool) References(key any) (int, bool) { |
| 202 | up.RLock() |
| 203 | upv, loaded := up.pool[key] |
| 204 | up.RUnlock() |
| 205 | if loaded { |
| 206 | // I wonder if it'd be safer to read this value during |
| 207 | // our lock on the UsagePool... guess we'll see... |
| 208 | refs := upv.refs.Load() |
| 209 | return int(refs), true |
| 210 | } |
| 211 | return 0, false |
| 212 | } |
| 213 | |
| 214 | // Constructor is a function that returns a new value |
| 215 | // that can destruct itself when it is no longer needed. |