From b3c3a9f1740f41d4e423e4b224e98ad6b5d328b3 Mon Sep 17 00:00:00 2001 From: James Tucker Date: Thu, 27 Apr 2023 17:09:30 -0700 Subject: [PATCH] syncs: add Map.Len to get the length of the Map I need this for a corp change where I have a set as a queue, and make a different decisison if the set is empty. Updates tailscale/corp#10344 Signed-off-by: James Tucker --- syncs/syncs.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/syncs/syncs.go b/syncs/syncs.go index aa89486a4..79acd8654 100644 --- a/syncs/syncs.go +++ b/syncs/syncs.go @@ -220,6 +220,13 @@ func (m *Map[K, V]) Range(f func(key K, value V) bool) { } } +// Len returns the length of the map. +func (m *Map[K, V]) Len() int { + m.mu.RLock() + defer m.mu.RUnlock() + return len(m.m) +} + // WaitGroup is identical to [sync.WaitGroup], // but provides a Go method to start a goroutine. type WaitGroup struct{ sync.WaitGroup }