Skip to content

Commit

Permalink
Do not panic on Unsub after Close
Browse files Browse the repository at this point in the history
  • Loading branch information
Chandra Sekar S committed Jan 6, 2013
1 parent e58e522 commit 6be93b3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pubsub.go
Expand Up @@ -169,6 +169,14 @@ func (ps *PubSub) removeTopic(topic string) {
}

func (ps *PubSub) remove(topic string, ch chan interface{}) {
if _, ok := ps.topics[topic]; !ok {
return
}

if _, ok := ps.topics[topic][ch]; !ok {
return
}

delete(ps.topics[topic], ch)
delete(ps.revTopics[ch], topic)

Expand Down
13 changes: 13 additions & 0 deletions pubsub_test.go
Expand Up @@ -89,6 +89,19 @@ func (s *Suite) TestClose(c *check.C) {
ps.Shutdown()
}

func (s *Suite) TestUnsubAfterClose(c *check.C) {
ps := New(1)
ch := ps.Sub("t1")
defer func() {
ps.Unsub(ch, "t1")
ps.Shutdown()
}()

ps.Close("t1")
_, ok := <-ch
c.Check(ok, check.Equals, false)
}

func (s *Suite) TestShutdown(c *check.C) {
start := runtime.NumGoroutine()
New(10).Shutdown()
Expand Down

0 comments on commit 6be93b3

Please sign in to comment.