From 8455869439805f328772d52e8851787b326cd323 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Tue, 17 Jun 2025 17:40:13 -0700 Subject: [PATCH] Add a `ThreadPool` async executor to `State` If we need to use simple async code in a few places, a single executor may be better than having several threads blocking on async code. This should probably use the calloop executor, but that's had issues in cosmic-workspaces, though that may not apply here. --- Cargo.lock | 1 + Cargo.toml | 1 + src/state.rs | 3 +++ 3 files changed, 5 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index e90210f5..e5e28b32 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -833,6 +833,7 @@ dependencies = [ "cosmic-text", "egui", "egui_plot", + "futures-executor", "i18n-embed", "i18n-embed-fl", "iced_tiny_skia", diff --git a/Cargo.toml b/Cargo.toml index a2ae94f6..394d19f8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -87,6 +87,7 @@ reis = { version = "0.5", features = ["calloop"] } clap_lex = "0.7" parking_lot = "0.12.5" logind-zbus = { version = "5.3.2", optional = true } +futures-executor = { version = "0.3.31", features = ["thread-pool"] } [dependencies.id_tree] branch = "feature/copy_clone" diff --git a/src/state.rs b/src/state.rs index 2e900845..1dc7b6ef 100644 --- a/src/state.rs +++ b/src/state.rs @@ -33,6 +33,7 @@ use crate::{ use anyhow::Context; use calloop::RegistrationToken; use cosmic_comp_config::output::comp::{OutputConfig, OutputState}; +use futures_executor::ThreadPool; use i18n_embed::{ DesktopLanguageRequester, fluent::{FluentLanguageLoader, fluent_language_loader}, @@ -211,6 +212,7 @@ pub struct Common { pub display_handle: DisplayHandle, pub event_loop_handle: LoopHandle<'static, State>, pub event_loop_signal: LoopSignal, + pub async_executor: ThreadPool, pub popups: PopupManager, pub shell: Arc>, @@ -710,6 +712,7 @@ impl State { display_handle: dh.clone(), event_loop_handle: handle, event_loop_signal: signal, + async_executor: ThreadPool::builder().pool_size(1).create().unwrap(), popups: PopupManager::default(), shell,