async: use tokio for thread block calls

This commit is contained in:
ardocrat
2025-04-02 19:15:20 +03:00
parent 3da8f5420b
commit a1b3330e5e
4 changed files with 16 additions and 18 deletions
+1 -1
View File
@@ -290,7 +290,7 @@ impl CameraContent {
// Launch scanner at separate thread.
thread::spawn(move || {
tokio::runtime::Builder::new_multi_thread()
tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap()
@@ -18,11 +18,9 @@ use egui::{Id, RichText};
use grin_core::core::{amount_from_hr_string, amount_to_hr_string};
use grin_wallet_libwallet::{Error, SlatepackAddress};
use parking_lot::RwLock;
use tor_rtcompat::ToplevelBlockOn;
use tor_rtcompat::tokio::TokioNativeTlsRuntime;
use crate::gui::Colors;
use crate::gui::platform::PlatformCallbacks;
use crate::gui::views::{CameraContent, Modal, View};
use crate::gui::views::types::TextEditOptions;
use crate::gui::views::wallets::wallet::WalletTransactionModal;
@@ -311,8 +309,10 @@ impl TransportSendModal {
let res = self.send_result.clone();
self.sending = true;
thread::spawn(move || {
let runtime = TokioNativeTlsRuntime::create().unwrap();
runtime
tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap()
.block_on(async {
let result = wallet.send_tor(a, &addr).await;
let mut w_res = res.write();
+8 -10
View File
@@ -14,8 +14,6 @@
#![windows_subsystem = "windows"]
use tor_rtcompat::ToplevelBlockOn;
pub fn main() {
#[allow(dead_code)]
#[cfg(not(target_os = "android"))]
@@ -113,7 +111,6 @@ fn start_desktop_gui(platform: grim::gui::platform::Desktop) {
let os = egui::os::OperatingSystem::from_target_os();
let (width, height) = AppConfig::window_size();
let mut viewport = egui::ViewportBuilder::default()
.with_min_inner_size([AppConfig::MIN_WIDTH, AppConfig::MIN_HEIGHT])
.with_inner_size([width, height]);
@@ -142,7 +139,6 @@ fn start_desktop_gui(platform: grim::gui::platform::Desktop) {
..Default::default()
};
// Use Glow renderer for Windows.
let is_win = os == egui::os::OperatingSystem::Windows;
options.renderer = if is_win {
eframe::Renderer::Glow
} else {
@@ -175,9 +171,10 @@ fn start_desktop_gui(platform: grim::gui::platform::Desktop) {
#[allow(dead_code)]
#[cfg(not(target_os = "android"))]
fn is_app_running(data: &Option<String>) -> bool {
use tor_rtcompat::ToplevelBlockOn;
let runtime = tor_rtcompat::tokio::TokioNativeTlsRuntime::create().unwrap();
let res: Result<(), Box<dyn std::error::Error>> = runtime
let res: Result<(), Box<dyn std::error::Error>> = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap()
.block_on(async {
use interprocess::local_socket::{
tokio::{prelude::*, Stream}
@@ -214,9 +211,10 @@ fn is_app_running(data: &Option<String>) -> bool {
#[cfg(not(target_os = "android"))]
fn start_app_socket(platform: grim::gui::platform::Desktop) {
std::thread::spawn(move || {
use tor_rtcompat::ToplevelBlockOn;
let runtime = tor_rtcompat::tokio::TokioNativeTlsRuntime::create().unwrap();
let _: Result<_, _> = runtime
let _ = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap()
.block_on(async {
use interprocess::local_socket::{
tokio::{prelude::*, Stream},
+2 -2
View File
@@ -78,7 +78,7 @@ impl ExternalConnection {
}
}
/// Check external connections availability.
/// Check external connection availability.
pub fn check(id: Option<i64>, ui_ctx: &egui::Context) {
let conn_list = ConnectionsConfig::ext_conn_list();
for conn in conn_list {
@@ -99,7 +99,7 @@ fn check_ext_conn(conn: &ExternalConnection, ui_ctx: &egui::Context) {
let ui_ctx = ui_ctx.clone();
ConnectionsConfig::update_ext_conn_status(conn.id, None);
std::thread::spawn(move || {
tokio::runtime::Builder::new_multi_thread()
tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap()