Skip to content
Snippets Groups Projects
Commit febd3569 authored by Cédric Moreau's avatar Cédric Moreau
Browse files

review: iodiomatic usage of stream

parent df2a0f54
No related branches found
No related tags found
1 merge request!316Resolve "Add RPC method to list peers"
......@@ -52,10 +52,11 @@ 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 {
stream
.for_each(|event| async {
match event {
DuniterPeeringEvent::GoodPeering(who, peering) => {
state.insert(PeeringWithId {
......@@ -68,7 +69,8 @@ impl DuniterPeeringsState {
}
_ => {}
}
}
})
.await
});
sink
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment