From c12634f8b2fae56a7f171a8183c236f20ef7cc0b Mon Sep 17 00:00:00 2001 From: Vladimir Bauer Date: Thu, 31 Oct 2024 19:24:36 +0500 Subject: [PATCH] join kak_h in the closure --- src/kamp/context.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/kamp/context.rs b/src/kamp/context.rs index fcd7a8a..760c545 100644 --- a/src/kamp/context.rs +++ b/src/kamp/context.rs @@ -177,11 +177,18 @@ impl Context { let out_h = self.read_fifo_out(tx); let kak_h = thread::spawn(move || kak::connect(self.session, cmd)); + let kak_check = || { + kak_h + .join() + .unwrap() + .map_err(|err| err.into()) + .and_then(|status| self.check_status(status)) + }; let res = match rx.recv().map_err(anyhow::Error::new) { Err(e) => { - let status = kak_h.join().unwrap()?; - return self.check_status(status).and_then(|_| Err(e.into())); + kak_check()?; + return Err(e.into()); } Ok(res) => res, }; @@ -194,7 +201,7 @@ impl Context { out_h.join().unwrap()?; } err_h.join().unwrap()?; - kak_h.join().unwrap()?; + kak_check()?; res.map(drop) }