Merge pull request #18 from libp2p/fix/fully-drain

fix: completely drain on close
This commit is contained in:
Łukasz Magiera 2019-06-27 22:15:01 +02:00 committed by GitHub
commit 04058af20a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -104,15 +104,10 @@ func (s *sub) Out() <-chan interface{} {
}
func (s *sub) Close() error {
stop := make(chan struct{})
go func() {
for {
select {
case <-s.ch:
case <-stop:
close(s.ch)
return
}
// drain the event channel, will return when closed and drained.
// this is necessary to unblock publishes to this channel.
for range s.ch {
}
}()
@ -135,7 +130,7 @@ func (s *sub) Close() error {
s.dropper(n.typ)
}
}
close(stop)
close(s.ch)
return nil
}