Commit 55d412ef authored by gammazero's avatar gammazero Committed by vyzo

Make close concurrent safe

parent e25f98c4
......@@ -2,6 +2,7 @@ package pubsub
import (
"context"
"sync"
)
// Subscription handles the details of a particular Topic subscription.
......@@ -10,9 +11,9 @@ type Subscription struct {
topic string
ch chan *Message
cancelCh chan<- *Subscription
closed bool
ctx context.Context
err error
once sync.Once
}
// Topic returns the topic string associated with the Subscription
......@@ -44,8 +45,7 @@ func (sub *Subscription) Cancel() {
}
func (sub *Subscription) close() {
if !sub.closed {
sub.once.Do(func() {
close(sub.ch)
sub.closed = true
}
})
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment