GetOrSetFunc gets the value for the given key, or sets it using the provided function if it doesn't exist. The function f is called outside the lock to avoid deadlocks. Returns the value and whether it was set (true) or already existed (false).
(key string, f func(key string) interface{})
| 188 | // The function f is called outside the lock to avoid deadlocks. |
| 189 | // Returns the value and whether it was set (true) or already existed (false). |
| 190 | func (slm ShardLockMaps) GetOrSetFunc(key string, f func(key string) interface{}) (interface{}, bool) { |
| 191 | if v, ok := slm.Get(key); ok { |
| 192 | return v, false |
| 193 | } |
| 194 | return slm.doSetWithLockCheck(key, f(key)) |
| 195 | } |
| 196 | |
| 197 | // GetOrSetFuncLock gets the value for the given key, or sets it using the provided function if it doesn't exist. |
| 198 | // The function f is called inside the lock for atomic operations. |