From e712e3b47c4c019463841a70c9eabba3bee42d3e Mon Sep 17 00:00:00 2001 From: QuantumEntangledAndy Date: Wed, 10 May 2023 10:26:53 +0700 Subject: [PATCH] Dedicated thread for the BC connection layer --- crates/core/src/bc_protocol/connection/bcconn.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/crates/core/src/bc_protocol/connection/bcconn.rs b/crates/core/src/bc_protocol/connection/bcconn.rs index 2512770..b2038d7 100644 --- a/crates/core/src/bc_protocol/connection/bcconn.rs +++ b/crates/core/src/bc_protocol/connection/bcconn.rs @@ -48,10 +48,17 @@ impl BcConnection { let mut rx_thread = JoinSet::>::new(); let thread_poll_commander = poll_commander.clone(); + let handle = tokio::task::spawn_blocking(move || { + let runtime = tokio::runtime::Builder::new_current_thread() + .build() + .unwrap(); + runtime.block_on( + PollSender::new(thread_poll_commander) + .send_all(&mut source.map(|bc| Ok(PollCommand::Bc(Box::new(bc))))), + ) + }); rx_thread.spawn(async move { - PollSender::new(thread_poll_commander) - .send_all(&mut source.map(|bc| Ok(PollCommand::Bc(Box::new(bc))))) - .await?; + handle.await??; Ok(()) });