From cc21b9baa168e982221481728e9baaf200732443 Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy Date: Fri, 27 Jan 2023 03:43:48 +0100 Subject: [PATCH] feat(executor): add cosmic::executor::Default --- examples/cosmic/src/window.rs | 2 +- src/executor/mod.rs | 7 +++++++ src/{single_thread_executor.rs => executor/single.rs} | 6 +++--- src/lib.rs | 5 ++--- 4 files changed, 13 insertions(+), 7 deletions(-) create mode 100644 src/executor/mod.rs rename src/{single_thread_executor.rs => executor/single.rs} (83%) diff --git a/examples/cosmic/src/window.rs b/examples/cosmic/src/window.rs index 589d9e82..1d5465ff 100644 --- a/examples/cosmic/src/window.rs +++ b/examples/cosmic/src/window.rs @@ -302,7 +302,7 @@ impl Window { } impl Application for Window { - type Executor = iced::executor::Default; + type Executor = cosmic::executor::Default; type Flags = (); type Message = Message; type Theme = Theme; diff --git a/src/executor/mod.rs b/src/executor/mod.rs new file mode 100644 index 00000000..5d53af80 --- /dev/null +++ b/src/executor/mod.rs @@ -0,0 +1,7 @@ +pub mod single; + +#[cfg(not(feature = "tokio"))] +pub type Default = iced::executor::Default; + +#[cfg(feature = "tokio")] +pub type Default = single::Executor; diff --git a/src/single_thread_executor.rs b/src/executor/single.rs similarity index 83% rename from src/single_thread_executor.rs rename to src/executor/single.rs index e9ee3187..ac09d0e7 100644 --- a/src/single_thread_executor.rs +++ b/src/executor/single.rs @@ -1,10 +1,10 @@ -use std::{future::Future, thread}; +use std::future::Future; #[cfg(feature = "tokio")] -pub struct SingleThreadExecutor(tokio::runtime::Runtime); +pub struct Executor(tokio::runtime::Runtime); #[cfg(feature = "tokio")] -impl iced_native::Executor for SingleThreadExecutor { +impl iced_native::Executor for Executor { fn new() -> Result { // Current thread executor requires calling `block_on` to actually run // futures. Main thread is busy with things other than running futures, diff --git a/src/lib.rs b/src/lib.rs index b9c450dd..fe232eaf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,15 +14,14 @@ pub use iced_winit; #[cfg(feature = "applet")] pub mod applet; +pub mod executor; pub mod font; pub mod keyboard_nav; pub mod theme; pub mod widget; #[cfg(feature = "tokio")] -mod single_thread_executor; -#[cfg(feature = "tokio")] -pub use single_thread_executor::SingleThreadExecutor; +pub use executor::single::Executor as SingleThreadExecutor; pub mod settings; pub use settings::settings;