Skip to content

Commit

Permalink
Stop now correctly clear the done channel after all the work groups stop
Browse files Browse the repository at this point in the history
  • Loading branch information
thrawn01 committed Aug 22, 2019
1 parent 3fb2ff5 commit 25f0568
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.1
3.0.2
9 changes: 6 additions & 3 deletions waitgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 25f0568

Please sign in to comment.