But in a peer to peer environment, it's different.
When you receive a peer discovery query, you need to return the nodes you're connected to, and so on.
This turned out to be a mess, as you had no clue in which order things were happening. That message being processed may be from a node we're no longer connected to.
The worst was if we accidentally connected twice to the same node, in which case we'd close the first connection.
But then parts would try to redirect to the 2nd connection, and you can imagine how complex that is.
The problem is that polling the rx alone doesn't do anything.
This further complexified the whole logic of the code.
Instead, the way libp2p now works is different.
More importantly, methods on the Swarm can be used to get the state of the network, and this state is updated only when polling.
It's only after you poll() and obtain a PeerDisconnected event that is_connected would stary returning false.
This made everything waaaay easier, as it eliminated all potential race conditions, and I'm confident that code that uses libp2p can now be robust.