diff --git a/node/src/endpoint_gossip/rpc/state.rs b/node/src/endpoint_gossip/rpc/state.rs index 75d8a2529f7ec51de59dad8df6bf09117aebb122..b9d69c1f419ea203a0b347583e8d318848b6864d 100644 --- a/node/src/endpoint_gossip/rpc/state.rs +++ b/node/src/endpoint_gossip/rpc/state.rs @@ -52,23 +52,25 @@ impl DuniterPeeringsState { /// Creates a channel for binding to the network events. pub fn listen(&self) -> TracingUnboundedSender<DuniterPeeringEvent> { - let (sink, mut stream) = tracing_unbounded("mpsc_duniter_peering_rpc_stream", 1_000); + let (sink, stream) = tracing_unbounded("mpsc_duniter_peering_rpc_stream", 1_000); let state = self.clone(); tokio::spawn(async move { - while let Some(event) = stream.next().await { - match event { - DuniterPeeringEvent::GoodPeering(who, peering) => { - state.insert(PeeringWithId { - peer_id: who.to_base58(), - endpoints: peering.endpoints, - }); + stream + .for_each(|event| async { + match event { + DuniterPeeringEvent::GoodPeering(who, peering) => { + state.insert(PeeringWithId { + peer_id: who.to_base58(), + endpoints: peering.endpoints, + }); + } + DuniterPeeringEvent::StreamClosed(who) => { + state.remove(who.to_base58()); + } + _ => {} } - DuniterPeeringEvent::StreamClosed(who) => { - state.remove(who.to_base58()); - } - _ => {} - } - } + }) + .await }); sink }