Allow switching executor::Default with features
This commit is contained in:
parent
e8316b2087
commit
ad500441af
6 changed files with 34 additions and 28 deletions
|
|
@ -5,38 +5,49 @@ pub use platform::Default;
|
|||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
mod platform {
|
||||
use iced_winit::{executor::ThreadPool, futures, Executor};
|
||||
use iced_futures::{executor, futures};
|
||||
|
||||
#[cfg(feature = "tokio")]
|
||||
type Executor = executor::Tokio;
|
||||
|
||||
#[cfg(all(not(feature = "tokio"), feature = "async-std"))]
|
||||
type Executor = executor::AsyncStd;
|
||||
|
||||
#[cfg(not(any(feature = "tokio", feature = "async-std")))]
|
||||
type Executor = executor::ThreadPool;
|
||||
|
||||
/// A default cross-platform executor.
|
||||
///
|
||||
/// - On native platforms, it will use a
|
||||
/// `iced_futures::executor::ThreadPool`.
|
||||
/// - On native platforms, it will use:
|
||||
/// - `iced_futures::executor::Tokio` when the `tokio` feature is enabled.
|
||||
/// - `iced_futures::executor::AsyncStd` when the `async-std` feature is
|
||||
/// enabled.
|
||||
/// - `iced_futures::executor::ThreadPool` otherwise.
|
||||
/// - On the Web, it will use `iced_futures::executor::WasmBindgen`.
|
||||
#[derive(Debug)]
|
||||
pub struct Default(ThreadPool);
|
||||
pub struct Default(Executor);
|
||||
|
||||
impl Executor for Default {
|
||||
impl super::Executor for Default {
|
||||
fn new() -> Result<Self, futures::io::Error> {
|
||||
Ok(Default(ThreadPool::new()?))
|
||||
Ok(Default(Executor::new()?))
|
||||
}
|
||||
|
||||
fn spawn(
|
||||
&self,
|
||||
future: impl futures::Future<Output = ()> + Send + 'static,
|
||||
) {
|
||||
self.0.spawn(future);
|
||||
let _ = self.0.spawn(future);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
mod platform {
|
||||
use iced_web::{executor::WasmBindgen, futures, Executor};
|
||||
use iced_futures::{executor::WasmBindgen, futures, Executor};
|
||||
|
||||
/// A default cross-platform executor.
|
||||
///
|
||||
/// - On native platforms, it will use a
|
||||
/// `iced_futures::executor::ThreadPool`.
|
||||
/// - On native platforms, it will use `iced_futures::executor::ThreadPool`.
|
||||
/// - On the Web, it will use `iced_futures::executor::WasmBindgen`.
|
||||
#[derive(Debug)]
|
||||
pub struct Default(WasmBindgen);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue