doSetWithLockCheckWithFunc performs a set operation with function execution inside lock
(key string, f func(key string) interface{})
| 221 | |
| 222 | // doSetWithLockCheckWithFunc performs a set operation with function execution inside lock |
| 223 | func (slm ShardLockMaps) doSetWithLockCheckWithFunc(key string, f func(key string) interface{}) (interface{}, bool) { |
| 224 | shard := slm.GetShard(key) |
| 225 | shard.Lock() |
| 226 | defer shard.Unlock() |
| 227 | |
| 228 | if got, ok := shard.items[key]; ok { |
| 229 | return got, false |
| 230 | } |
| 231 | |
| 232 | val := f(key) |
| 233 | shard.items[key] = val |
| 234 | return val, true |
| 235 | } |
| 236 | |
| 237 | // Clear removes all items from map. |
| 238 | func (slm ShardLockMaps) Clear() { |
no test coverage detected