From 5c0abab1b7bf0f2858c451d6f0efc7ca0e138fc6 Mon Sep 17 00:00:00 2001 From: hozan23 Date: Sat, 29 Jun 2024 21:16:46 +0200 Subject: use shadown variables to name clones and place them between {} when spawning new tasks --- p2p/src/peer/mod.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'p2p/src/peer/mod.rs') diff --git a/p2p/src/peer/mod.rs b/p2p/src/peer/mod.rs index 2068789..6903294 100644 --- a/p2p/src/peer/mod.rs +++ b/p2p/src/peer/mod.rs @@ -209,16 +209,17 @@ impl Peer { self.protocol_ids.write().await.push(protocol_id.clone()); - let selfc = self.clone(); - let proto_idc = protocol_id.clone(); - - let on_failure = |result: TaskResult>| async move { - if let TaskResult::Completed(res) = result { - if res.is_err() { - error!("protocol {} stopped", proto_idc); + let on_failure = { + let this = self.clone(); + let protocol_id = protocol_id.clone(); + |result: TaskResult>| async move { + if let TaskResult::Completed(res) = result { + if res.is_err() { + error!("protocol {} stopped", protocol_id); + } + // Send a stop signal to read loop + let _ = this.stop_chan.0.try_send(res); } - // Send a stop signal to read loop - let _ = selfc.stop_chan.0.try_send(res); } }; -- cgit v1.2.3