From 080e15a9553c958a0bf0a1ec12d641309f7a2c48 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 16 Aug 2024 17:41:46 +0200 Subject: [PATCH] BatchSliceOfStrings(): panic if count <= 0 Otherwise, 0 would lead to infinite empty slices. Negative numbers already crash the program. --- utils/utils.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/utils/utils.go b/utils/utils.go index 8e246ab4..3db1330b 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -30,7 +30,12 @@ func Timed(start time.Time, callback func(elapsed time.Duration)) { } // BatchSliceOfStrings groups the given keys into chunks of size count and streams them into a returned channel. +// Panics if count is less than or equal to zero. func BatchSliceOfStrings(ctx context.Context, keys []string, count int) <-chan []string { + if count <= 0 { + panic("chunk size must be greater than zero") + } + batches := make(chan []string) go func() {