Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Do not panic on Unsub after Close

  • Loading branch information...
commit 6be93b38bc9fea20161453c23d75bcbd8546f82c 1 parent e58e522
@tuxychandru authored
Showing with 21 additions and 0 deletions.
  1. +8 −0 pubsub.go
  2. +13 −0 pubsub_test.go
View
8 pubsub.go
@@ -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
13 pubsub_test.go
@@ -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()
Please sign in to comment.
Something went wrong with that request. Please try again.