Skip to content

Commit

Permalink
Fix: more than one closing of done channel
Browse files Browse the repository at this point in the history
  • Loading branch information
olebedev committed Mar 24, 2016
1 parent 8f03f14 commit 3e7ff9a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
17 changes: 8 additions & 9 deletions emitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,16 +252,15 @@ func (e *Emitter) Emit(topic string, args ...interface{}) chan struct{} {
}
}

if haveToWait {
go func(done chan struct{}) {
defer func() { recover() }()
wg.Wait()
close(done)
}(done)
} else {
}
if haveToWait {
go func(done chan struct{}) {
defer func() { recover() }()
wg.Wait()
close(done)
}

}(done)
} else {
close(done)
}

e.mu.Unlock()
Expand Down
7 changes: 7 additions & 0 deletions emitter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,13 @@ func TestSync(t *testing.T) {
expect(t, isOpened, true)
_, isOpened = <-pipe2
expect(t, isOpened, false)

// void
ee = New(0)
ee.Once("*", Void)
ee.On("test:void", Void, func(e *Event) {
})
<-ee.Emit("test:void")
}

func expect(t *testing.T, a interface{}, b interface{}) {
Expand Down

0 comments on commit 3e7ff9a

Please sign in to comment.