I am handling p2p in a struct with swarm. I am working with streams, gossip and I do have separate tasks for them. So that I have to use tokio::sync::Mutex for Swarm. The swarm’s select_next_some()
is blocking and it means that I can’t read swarm events and publish from different tasks because I am getting a deadlock. The deadlock happens when I need to obtain let mut swarm = self.swarm.lock().await followed by await'ing an event from swarm
, it blocks and I can not obtain lock in order to publish in it. Is there best practices to resolve that?