RemoveCb locks the shard containing the key, retrieves its current value and calls the callback with those params If callback returns true and element exists, it will remove it from the map Returns the value returned by the callback (even if element was not present in the map)
(key string, cb RemoveCb)
| 153 | // If callback returns true and element exists, it will remove it from the map |
| 154 | // Returns the value returned by the callback (even if element was not present in the map) |
| 155 | func (slm ShardLockMaps) RemoveCb(key string, cb RemoveCb) bool { |
| 156 | |
| 157 | shard := slm.GetShard(key) |
| 158 | shard.Lock() |
| 159 | v, ok := shard.items[key] |
| 160 | remove := cb(key, v, ok) |
| 161 | if remove && ok { |
| 162 | delete(shard.items, key) |
| 163 | } |
| 164 | shard.Unlock() |
| 165 | return remove |
| 166 | } |
| 167 | |
| 168 | // Pop removes an element from the map and returns it |
| 169 | func (slm ShardLockMaps) Pop(key string) (v interface{}, exists bool) { |