From 861bb84b1e6bee270e59a6a81948b6ddc1472641 Mon Sep 17 00:00:00 2001 From: vyzo Date: Mon, 12 Jul 2021 19:27:01 +0300 Subject: [PATCH] emit new peer notification without holding the semaphore --- notify.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/notify.go b/notify.go index 34feb7c1..6deb5aae 100644 --- a/notify.go +++ b/notify.go @@ -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: @@ -61,10 +59,6 @@ func (p *PubSubNotif) Initialize() { select { case <-p.newPeersSema: - defer func() { - p.newPeersSema <- struct{}{} - }() - case <-p.ctx.Done(): return } @@ -76,6 +70,8 @@ func (p *PubSubNotif) Initialize() { p.newPeersPend[pid] = struct{}{} } + p.newPeersSema <- struct{}{} + select { case p.newPeers <- struct{}{}: default: