From 1c6c11212c7e78223a8bd6ab6bb10ff5cb584bc9 Mon Sep 17 00:00:00 2001 From: Maxime WEYL Date: Mon, 9 Dec 2024 23:21:39 +0100 Subject: [PATCH] Fix https://github.com/onsi/gomega/issues/803 --- gmeasure/experiment.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gmeasure/experiment.go b/gmeasure/experiment.go index a8341c5e6..39d55f1b2 100644 --- a/gmeasure/experiment.go +++ b/gmeasure/experiment.go @@ -463,13 +463,19 @@ func (e *Experiment) Sample(callback func(idx int), samplingConfig SamplingConfi minSamplingInterval := samplingConfig.MinSamplingInterval work := make(chan int) - defer close(work) + var wg sync.WaitGroup + defer func() { + close(work) + wg.Wait() + }() if numParallel > 1 { for worker := 0; worker < numParallel; worker++ { go func() { + wg.Add(1) for idx := range work { callback(idx) } + wg.Done() }() } }