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 --- jsonrpc/src/client/mod.rs | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'jsonrpc/src/client') diff --git a/jsonrpc/src/client/mod.rs b/jsonrpc/src/client/mod.rs index 43ce5fc..6f6bd97 100644 --- a/jsonrpc/src/client/mod.rs +++ b/jsonrpc/src/client/mod.rs @@ -260,20 +260,26 @@ impl Client { } fn start_background_loop(self: &Arc, conn: Conn) { - let selfc = self.clone(); - let on_complete = |result: TaskResult>| async move { - if let TaskResult::Completed(Err(err)) = result { - error!("Client stopped: {err}"); + let on_complete = { + let this = self.clone(); + |result: TaskResult>| async move { + if let TaskResult::Completed(Err(err)) = result { + error!("Client stopped: {err}"); + } + this.disconnect.store(true, Ordering::Relaxed); + this.subscriptions.clear().await; + this.message_dispatcher.clear().await; } - selfc.disconnect.store(true, Ordering::Relaxed); - selfc.subscriptions.clear().await; - selfc.message_dispatcher.clear().await; }; - let selfc = self.clone(); // Spawn a new task - self.task_group - .spawn(selfc.background_loop(conn), on_complete); + self.task_group.spawn( + { + let this = self.clone(); + async move { this.background_loop(conn).await } + }, + on_complete, + ); } async fn background_loop(self: Arc, conn: Conn) -> Result<()> { -- cgit v1.2.3