don't use futures-executor when it's not the default executor

This commit is contained in:
edwloef 2025-03-13 23:12:44 +01:00 committed by Héctor Ramón Jiménez
parent a3a7503eef
commit baadcc150f
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
12 changed files with 41 additions and 12 deletions

1
Cargo.lock generated
View file

@ -2777,6 +2777,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"console_error_panic_hook", "console_error_panic_hook",
"console_log", "console_log",
"futures",
"iced_wgpu", "iced_wgpu",
"iced_widget", "iced_widget",
"iced_winit", "iced_winit",

View file

@ -22,7 +22,7 @@ all-features = true
maintenance = { status = "actively-developed" } maintenance = { status = "actively-developed" }
[features] [features]
default = ["wgpu", "tiny-skia", "auto-detect-theme"] default = ["wgpu", "tiny-skia", "auto-detect-theme", "futures-executor"]
# Enables the `wgpu` GPU-accelerated renderer backend # Enables the `wgpu` GPU-accelerated renderer backend
wgpu = ["iced_renderer/wgpu", "iced_widget/wgpu"] wgpu = ["iced_renderer/wgpu", "iced_widget/wgpu"]
# Enables the `tiny-skia` software renderer backend # Enables the `tiny-skia` software renderer backend
@ -43,6 +43,8 @@ markdown = ["iced_widget/markdown"]
lazy = ["iced_widget/lazy"] lazy = ["iced_widget/lazy"]
# Enables a debug view in native platforms (press F12) # Enables a debug view in native platforms (press F12)
debug = ["iced_winit/debug"] debug = ["iced_winit/debug"]
# Enables `futures-executor` as the `executor::Default` on native platforms
futures-executor = ["iced_futures/thread-pool"]
# Enables `tokio` as the `executor::Default` on native platforms # Enables `tokio` as the `executor::Default` on native platforms
tokio = ["iced_futures/tokio"] tokio = ["iced_futures/tokio"]
# Enables `async-std` as the `executor::Default` on native platforms # Enables `async-std` as the `executor::Default` on native platforms
@ -150,7 +152,7 @@ bytemuck = { version = "1.0", features = ["derive"] }
bytes = "1.6" bytes = "1.6"
cosmic-text = "0.13" cosmic-text = "0.13"
dark-light = "2.0" dark-light = "2.0"
futures = "0.3" futures = { version = "0.3", default-features = false, features = ["std", "async-await"] }
glam = "0.25" glam = "0.25"
cryoglyph = { git = "https://github.com/iced-rs/cryoglyph.git", rev = "be2defe4a13fd7c97c6f4c81e8e085463eb578dc" } cryoglyph = { git = "https://github.com/iced-rs/cryoglyph.git", rev = "be2defe4a13fd7c97c6f4c81e8e085463eb578dc" }
guillotiere = "0.6" guillotiere = "0.6"

View file

@ -12,6 +12,9 @@ iced_wgpu.workspace = true
iced_widget.workspace = true iced_widget.workspace = true
iced_widget.features = ["wgpu"] iced_widget.features = ["wgpu"]
futures.workspace = true
futures.features = ["thread-pool"]
[target.'cfg(not(target_arch = "wasm32"))'.dependencies] [target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tracing-subscriber = "0.3" tracing-subscriber = "0.3"

View file

@ -13,6 +13,10 @@ impl crate::Executor for Executor {
fn spawn(&self, future: impl Future<Output = ()> + Send + 'static) { fn spawn(&self, future: impl Future<Output = ()> + Send + 'static) {
let _ = async_std::task::spawn(future); let _ = async_std::task::spawn(future);
} }
fn block_on(future: impl Future<Output = ()> + 'static) {
async_std::task::block_on(future);
}
} }
pub mod time { pub mod time {

View file

@ -12,6 +12,10 @@ impl crate::Executor for Executor {
fn spawn(&self, future: impl Future<Output = ()> + Send + 'static) { fn spawn(&self, future: impl Future<Output = ()> + Send + 'static) {
smol::spawn(future).detach(); smol::spawn(future).detach();
} }
fn block_on(future: impl Future<Output = ()> + 'static) {
smol::block_on(future);
}
} }
pub mod time { pub mod time {

View file

@ -11,6 +11,10 @@ impl crate::Executor for Executor {
fn spawn(&self, future: impl Future<Output = ()> + Send + 'static) { fn spawn(&self, future: impl Future<Output = ()> + Send + 'static) {
self.spawn_ok(future); self.spawn_ok(future);
} }
fn block_on(future: impl Future<Output = ()> + 'static) {
futures::executor::block_on(future);
}
} }
pub mod time { pub mod time {

View file

@ -17,6 +17,13 @@ impl crate::Executor for Executor {
let _guard = tokio::runtime::Runtime::enter(self); let _guard = tokio::runtime::Runtime::enter(self);
f() f()
} }
fn block_on(future: impl Future<Output = ()> + 'static) {
tokio::runtime::Builder::new_current_thread()
.build()
.unwrap()
.block_on(future);
}
} }
pub mod time { pub mod time {

View file

@ -14,6 +14,12 @@ impl crate::Executor for Executor {
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
fn spawn(&self, _future: impl Future<Output = ()> + 'static) {} fn spawn(&self, _future: impl Future<Output = ()> + 'static) {}
#[cfg(not(target_arch = "wasm32"))]
fn block_on(_future: impl Future<Output = ()> + 'static) {}
#[cfg(target_arch = "wasm32")]
fn block_on(_future: impl Future<Output = ()> + 'static) {}
} }
pub mod time { pub mod time {

View file

@ -12,6 +12,10 @@ impl crate::Executor for Executor {
fn spawn(&self, future: impl futures::Future<Output = ()> + 'static) { fn spawn(&self, future: impl futures::Future<Output = ()> + 'static) {
wasm_bindgen_futures::spawn_local(future); wasm_bindgen_futures::spawn_local(future);
} }
fn block_on(future: impl futures::Future<Output = ()> + 'static) {
wasm_bindgen_futures::spawn_local(future);
}
} }
pub mod time { pub mod time {

View file

@ -20,4 +20,7 @@ pub trait Executor: Sized {
fn enter<R>(&self, f: impl FnOnce() -> R) -> R { fn enter<R>(&self, f: impl FnOnce() -> R) -> R {
f() f()
} }
/// Runs the future on the current thread, blocking it until it is completed.
fn block_on(future: impl Future<Output = ()> + 'static);
} }

View file

@ -21,7 +21,6 @@ multi-window = []
bytes.workspace = true bytes.workspace = true
iced_core.workspace = true iced_core.workspace = true
iced_futures.workspace = true iced_futures.workspace = true
iced_futures.features = ["thread-pool"]
raw-window-handle.workspace = true raw-window-handle.workspace = true
sipper.workspace = true sipper.workspace = true

View file

@ -662,15 +662,7 @@ async fn run_instance<P, C>(
} }
}; };
#[cfg(not(target_arch = "wasm32"))] P::Executor::block_on(create_compositor);
crate::futures::futures::executor::block_on(
create_compositor,
);
#[cfg(target_arch = "wasm32")]
{
wasm_bindgen_futures::spawn_local(create_compositor);
}
continue; continue;
} }