From 2e9a3a9a5d88e1548e33d4083c69264808a30076 Mon Sep 17 00:00:00 2001 From: thanhpp Date: Fri, 5 Jul 2024 11:53:52 +0700 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20syncmap:=20add=20clears?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: thanhpp --- x/syncmap/syncmap.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/x/syncmap/syncmap.go b/x/syncmap/syncmap.go index 305e224..47ffd26 100644 --- a/x/syncmap/syncmap.go +++ b/x/syncmap/syncmap.go @@ -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 @@ -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) +}