Remove Executor::block_on and simplify Compositor creation

This commit is contained in:
Héctor Ramón Jiménez 2025-04-02 10:39:27 +02:00
parent baadcc150f
commit 57cb14ce38
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
13 changed files with 58 additions and 108 deletions

View file

@ -24,6 +24,8 @@ thread-pool = ["futures/thread-pool"]
iced_core.workspace = true
futures.workspace = true
futures.features = ["std"]
log.workspace = true
rustc-hash.workspace = true

View file

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

View file

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

View file

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

View file

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

View file

@ -1,4 +1,5 @@
//! A backend that does nothing!
use crate::MaybeSend;
/// An executor that drops all the futures, instead of spawning them.
#[derive(Debug)]
@ -9,17 +10,7 @@ impl crate::Executor for Executor {
Ok(Self)
}
#[cfg(not(target_arch = "wasm32"))]
fn spawn(&self, _future: impl Future<Output = ()> + Send + 'static) {}
#[cfg(target_arch = "wasm32")]
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) {}
fn spawn(&self, _future: impl Future<Output = ()> + MaybeSend + 'static) {}
}
pub mod time {

View file

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

View file

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

View file

@ -1,6 +1,6 @@
//! Run commands and keep track of subscriptions.
use crate::subscription;
use crate::{BoxFuture, BoxStream, Executor, MaybeSend};
use crate::{BoxStream, Executor, MaybeSend};
use futures::{Sink, channel::mpsc};
use std::marker::PhantomData;
@ -51,20 +51,10 @@ where
}
/// Spawns a [`Future`] in the [`Runtime`].
///
/// The resulting `Message` will be forwarded to the `Sender` of the
/// [`Runtime`].
///
/// [`Future`]: BoxFuture
pub fn spawn(&mut self, future: BoxFuture<Message>) {
use futures::{FutureExt, SinkExt};
let mut sender = self.sender.clone();
let future = future.then(|message| async move {
let _ = sender.send(message).await;
});
pub fn spawn(
&mut self,
future: impl Future<Output = ()> + MaybeSend + 'static,
) {
self.executor.spawn(future);
}