Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
p2p
go-p2p-pubsub
Commits
55d412ef
Commit
55d412ef
authored
Jun 14, 2021
by
gammazero
Committed by
vyzo
Jun 15, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make close concurrent safe
parent
e25f98c4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
4 deletions
+4
-4
subscription.go
subscription.go
+4
-4
No files found.
subscription.go
View file @
55d412ef
...
@@ -2,6 +2,7 @@ package pubsub
...
@@ -2,6 +2,7 @@ package pubsub
import
(
import
(
"context"
"context"
"sync"
)
)
// Subscription handles the details of a particular Topic subscription.
// Subscription handles the details of a particular Topic subscription.
...
@@ -10,9 +11,9 @@ type Subscription struct {
...
@@ -10,9 +11,9 @@ type Subscription struct {
topic
string
topic
string
ch
chan
*Message
ch
chan
*Message
cancelCh
chan
<- *Subscription
cancelCh
chan
<- *Subscription
closed
bool
ctx context.Context
ctx context.Context
err
error
err
error
once sync.Once
}
}
// Topic returns the topic string associated with the Subscription
// Topic returns the topic string associated with the Subscription
...
@@ -44,8 +45,7 @@ func (sub *Subscription) Cancel() {
...
@@ -44,8 +45,7 @@ func (sub *Subscription) Cancel() {
}
}
func
(sub *Subscription)
close
() {
func
(sub *Subscription)
close
() {
if
!sub.closed
{
sub.once.Do(
func
()
{
close
(sub.ch)
close
(sub.ch)
sub.closed = true
})
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment