From bcccab1669876abce2560457602321775e6903e1 Mon Sep 17 00:00:00 2001 From: Baraka Andrew Date: Fri, 17 Dec 2021 14:46:06 +0900 Subject: [PATCH] panic when accessing map elements before initializing --- concurrent_map.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/concurrent_map.go b/concurrent_map.go index 60386a2..7e7f1e4 100644 --- a/concurrent_map.go +++ b/concurrent_map.go @@ -198,6 +198,10 @@ func (m ConcurrentMap) Clear() { // It returns once the size of each buffered channel is determined, // before all the channels are populated using goroutines. func snapshot(m ConcurrentMap) (chans []chan Tuple) { + //When you access map items before initializing. + if len(m) == 0{ + panic(`cmap.ConcurrentMap is not initialized. Should run New() before usage.`) + } chans = make([]chan Tuple, SHARD_COUNT) wg := sync.WaitGroup{} wg.Add(SHARD_COUNT)