sync: implement map.LoadAndDelete

This commit is contained in:
Tim Schaub
2022-09-01 14:01:13 -06:00
committed by Ron Evans
parent e09bd5abb3
commit 623dd6a815
2 changed files with 30 additions and 0 deletions
+11
View File
@@ -34,6 +34,17 @@ func (m *Map) LoadOrStore(key, value interface{}) (actual interface{}, loaded bo
return value, false
}
func (m *Map) LoadAndDelete(key interface{}) (value interface{}, loaded bool) {
m.lock.Lock()
defer m.lock.Unlock()
value, ok := m.m[key]
if !ok {
return nil, false
}
delete(m.m, key)
return value, true
}
func (m *Map) Store(key, value interface{}) {
m.lock.Lock()
defer m.lock.Unlock()