Skip to content

Commit

Permalink
emit new peer notification without holding the semaphore
Browse files Browse the repository at this point in the history
  • Loading branch information
vyzo committed Jul 13, 2021
1 parent ac4a401 commit 861bb84
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@ func (p *PubSubNotif) Connected(n network.Network, c network.Conn) {

select {
case <-p.newPeersSema:
defer func() {
p.newPeersSema <- struct{}{}
}()

case <-p.ctx.Done():
return
}

p.newPeersPend[c.RemotePeer()] = struct{}{}
p.newPeersSema <- struct{}{}

select {
case p.newPeers <- struct{}{}:
default:
Expand Down Expand Up @@ -61,10 +59,6 @@ func (p *PubSubNotif) Initialize() {

select {
case <-p.newPeersSema:
defer func() {
p.newPeersSema <- struct{}{}
}()

case <-p.ctx.Done():
return
}
Expand All @@ -76,6 +70,8 @@ func (p *PubSubNotif) Initialize() {
p.newPeersPend[pid] = struct{}{}
}

p.newPeersSema <- struct{}{}

select {
case p.newPeers <- struct{}{}:
default:
Expand Down

0 comments on commit 861bb84

Please sign in to comment.