Permalink
Browse files

Do not panic on Unsub after Close

  • Loading branch information...
1 parent e58e522 commit 6be93b38bc9fea20161453c23d75bcbd8546f82c Chandra Sekar S committed Jan 6, 2013
Showing with 21 additions and 0 deletions.
  1. +8 −0 pubsub.go
  2. +13 −0 pubsub_test.go
View
@@ -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)
View
@@ -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()

0 comments on commit 6be93b3

Please sign in to comment.