GetOrSetFuncLock gets the value for the given key, or sets it using the provided function if it doesn't exist. The function f is called inside the lock for atomic operations. WARNING: Do not perform operations on the container within f to avoid deadlocks. Returns the value and whether it was set (tr
(key string, f func(key string) interface{})
| 199 | // WARNING: Do not perform operations on the container within f to avoid deadlocks. |
| 200 | // Returns the value and whether it was set (true) or already existed (false). |
| 201 | func (slm ShardLockMaps) GetOrSetFuncLock(key string, f func(key string) interface{}) (interface{}, bool) { |
| 202 | if v, ok := slm.Get(key); ok { |
| 203 | return v, false |
| 204 | } |
| 205 | return slm.doSetWithLockCheckWithFunc(key, f) |
| 206 | } |
| 207 | |
| 208 | // doSetWithLockCheck performs a set operation with lock checking |
| 209 | func (slm ShardLockMaps) doSetWithLockCheck(key string, val interface{}) (interface{}, bool) { |