Skip to content

Commit

Permalink
skip disconnect events if the message sender does not need them
Browse files Browse the repository at this point in the history
  • Loading branch information
aschmahmann committed May 12, 2021
1 parent c22b4bf commit 57eeffe
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions subscriber_notifee.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ type disconnector interface {

func (nn *subscriberNotifee) Disconnected(n network.Network, v network.Conn) {
dht := nn.dht

ms, ok := dht.msgSender.(disconnector)
if !ok {
return
}

select {
case <-dht.Process().Closing():
return
Expand All @@ -178,9 +184,7 @@ func (nn *subscriberNotifee) Disconnected(n network.Network, v network.Conn) {
return
}

if ms, ok := dht.msgSender.(disconnector); ok {
ms.OnDisconnect(dht.Context(), p)
}
ms.OnDisconnect(dht.Context(), p)
}

func (nn *subscriberNotifee) Connected(network.Network, network.Conn) {}
Expand Down

0 comments on commit 57eeffe

Please sign in to comment.