Skip to content

Commit 59122e3

Browse files
committed
do the notification in a goroutine
don't block the swarm while waiting for the semaphore.
1 parent 73e3309 commit 59122e3

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

notify.go

+13-11
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,21 @@ func (p *PubSubNotif) Connected(n network.Network, c network.Conn) {
2222
return
2323
}
2424

25-
select {
26-
case <-p.newPeersSema:
27-
case <-p.ctx.Done():
28-
return
29-
}
25+
go func() {
26+
select {
27+
case <-p.newPeersSema:
28+
case <-p.ctx.Done():
29+
return
30+
}
3031

31-
p.newPeersPend[c.RemotePeer()] = struct{}{}
32-
p.newPeersSema <- struct{}{}
32+
p.newPeersPend[c.RemotePeer()] = struct{}{}
33+
p.newPeersSema <- struct{}{}
3334

34-
select {
35-
case p.newPeers <- struct{}{}:
36-
default:
37-
}
35+
select {
36+
case p.newPeers <- struct{}{}:
37+
default:
38+
}
39+
}()
3840
}
3941

4042
func (p *PubSubNotif) Disconnected(n network.Network, c network.Conn) {

0 commit comments

Comments
 (0)