Skip to content

Commit

Permalink
Merge pull request #44 from mailgun/thrawn/develop
Browse files Browse the repository at this point in the history
fixed WaitGroup.Go()
  • Loading branch information
thrawn01 authored Feb 13, 2019
2 parents 5488fd5 + dc0dabc commit 769f8d7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.4
2.3.5
8 changes: 1 addition & 7 deletions waitgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,8 @@ func (wg *WaitGroup) Run(callBack func(interface{}) error, data interface{}) {
func (wg *WaitGroup) Go(cb func()) {
wg.wg.Add(1)
go func() {
err := cb
if err == nil {
wg.wg.Done()
return
}
wg.mutex.Lock()
cb()
wg.wg.Done()
wg.mutex.Unlock()
}()
}

Expand Down
14 changes: 14 additions & 0 deletions waitgroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,31 @@ func (s *WaitGroupTestSuite) TestRun() {

func (s *WaitGroupTestSuite) TestGo() {
var wg holster.WaitGroup
result := make(chan struct{})

wg.Go(func() {
// Do some long running thing
time.Sleep(time.Nanosecond * 500)
result <- struct{}{}
})

wg.Go(func() {
// Do some long running thing
time.Sleep(time.Nanosecond * 50)
result <- struct{}{}
})

OUT:
for i := 0; i < 2; {
select {
case <-result:
i++
case <-time.After(time.Second):
s.Fail("waited to long for Go() to run")
break OUT
}
}

errs := wg.Wait()
s.Nil(errs)
}
Expand Down

0 comments on commit 769f8d7

Please sign in to comment.