From 25f0568afcbe0040263edfdd27ed202136a4b88d Mon Sep 17 00:00:00 2001 From: "Derrick J. Wippler" Date: Thu, 22 Aug 2019 14:43:44 -0500 Subject: [PATCH] Stop now correctly clear the done channel after all the work groups stop --- version | 2 +- waitgroup.go | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/version b/version index cb2b00e4..b5021469 100644 --- a/version +++ b/version @@ -1 +1 @@ -3.0.1 +3.0.2 diff --git a/waitgroup.go b/waitgroup.go index 1daa5c26..e1c0f66d 100644 --- a/waitgroup.go +++ b/waitgroup.go @@ -71,14 +71,17 @@ func (wg *WaitGroup) Until(callBack func(done chan struct{}) bool) { }() } -// closes the done channel passed into `Until()` calls and waits for the `Until()` callBack to return false +// Stop closes the done channel passed into `Until()` calls and waits for +// the `Until()` callBack to return false. func (wg *WaitGroup) Stop() { wg.mutex.Lock() + defer wg.mutex.Unlock() + if wg.done != nil { close(wg.done) } - wg.mutex.Unlock() - wg.Wait() + wg.wg.Wait() + wg.done = nil } // Run a goroutine in a loop continuously, if the callBack returns false the loop is broken