GetOrSet gets the value for the given key, or sets it if it doesn't exist. Returns the value and whether it was set (true) or already existed (false).
(key string, value interface{})
| 178 | // GetOrSet gets the value for the given key, or sets it if it doesn't exist. |
| 179 | // Returns the value and whether it was set (true) or already existed (false). |
| 180 | func (slm ShardLockMaps) GetOrSet(key string, value interface{}) (interface{}, bool) { |
| 181 | if v, ok := slm.Get(key); ok { |
| 182 | return v, false |
| 183 | } |
| 184 | return slm.doSetWithLockCheck(key, value) |
| 185 | } |
| 186 | |
| 187 | // GetOrSetFunc gets the value for the given key, or sets it using the provided function if it doesn't exist. |
| 188 | // The function f is called outside the lock to avoid deadlocks. |