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
Branches
Tags
1 merge request!316Resolve "Add RPC method to list peers"
...@@ -52,10 +52,11 @@ impl DuniterPeeringsState { ...@@ -52,10 +52,11 @@ impl DuniterPeeringsState {
/// Creates a channel for binding to the network events. /// Creates a channel for binding to the network events.
pub fn listen(&self) -> TracingUnboundedSender<DuniterPeeringEvent> { 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(); let state = self.clone();
tokio::spawn(async move { tokio::spawn(async move {
while let Some(event) = stream.next().await { stream
.for_each(|event| async {
match event { match event {
DuniterPeeringEvent::GoodPeering(who, peering) => { DuniterPeeringEvent::GoodPeering(who, peering) => {
state.insert(PeeringWithId { state.insert(PeeringWithId {
...@@ -68,7 +69,8 @@ impl DuniterPeeringsState { ...@@ -68,7 +69,8 @@ impl DuniterPeeringsState {
} }
_ => {} _ => {}
} }
} })
.await
}); });
sink sink
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment