Skip to content

Commit

Permalink
feat: ✨ syncmap: add clears
Browse files Browse the repository at this point in the history
Signed-off-by: thanhpp <[email protected]>
  • Loading branch information
thanhpp committed Jul 5, 2024
1 parent ef6f2cd commit 2e9a3a9
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion x/syncmap/syncmap.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package syncmap

import "sync"
import (
"sync"

"golang.org/x/exp/maps"
)

type SyncMap[K comparable, V any] struct {
data map[K]V
Expand Down Expand Up @@ -74,3 +78,10 @@ func (m *SyncMap[K, V]) RangeMut(fn func(k K, v V) bool) {
}
}
}

func (m *SyncMap[K, V]) Clears() {
m.rw.Lock()
defer m.rw.Unlock()

maps.Clear(m.data)
}

0 comments on commit 2e9a3a9

Please sign in to comment.