2020-01-20 05:43:09 +01:00
|
|
|
//! Choose your preferred executor to power your application.
|
2020-10-17 08:46:16 +02:00
|
|
|
pub use crate::runtime::Executor;
|
2020-01-20 05:43:09 +01:00
|
|
|
|
|
|
|
|
pub use platform::Default;
|
|
|
|
|
|
|
|
|
|
#[cfg(not(target_arch = "wasm32"))]
|
|
|
|
|
mod platform {
|
2020-02-06 03:56:21 +01:00
|
|
|
use iced_futures::{executor, futures};
|
|
|
|
|
|
2020-11-25 03:06:24 +01:00
|
|
|
#[cfg(feature = "tokio_old")]
|
|
|
|
|
type Executor = executor::TokioOld;
|
|
|
|
|
|
|
|
|
|
#[cfg(all(not(feature = "tokio_old"), feature = "tokio"))]
|
2020-02-06 03:56:21 +01:00
|
|
|
type Executor = executor::Tokio;
|
|
|
|
|
|
2020-11-25 03:06:24 +01:00
|
|
|
#[cfg(all(
|
|
|
|
|
not(any(feature = "tokio_old", feature = "tokio")),
|
|
|
|
|
feature = "async-std"
|
|
|
|
|
))]
|
2020-02-06 03:56:21 +01:00
|
|
|
type Executor = executor::AsyncStd;
|
|
|
|
|
|
2020-11-25 03:06:24 +01:00
|
|
|
#[cfg(not(any(
|
|
|
|
|
feature = "tokio_old",
|
|
|
|
|
feature = "tokio",
|
|
|
|
|
feature = "async-std"
|
|
|
|
|
)))]
|
2020-02-06 03:56:21 +01:00
|
|
|
type Executor = executor::ThreadPool;
|
2020-01-20 05:43:09 +01:00
|
|
|
|
|
|
|
|
/// A default cross-platform executor.
|
|
|
|
|
///
|
2020-02-06 03:56:21 +01:00
|
|
|
/// - 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.
|
2020-01-20 05:43:09 +01:00
|
|
|
/// - On the Web, it will use `iced_futures::executor::WasmBindgen`.
|
|
|
|
|
#[derive(Debug)]
|
2020-02-06 03:56:21 +01:00
|
|
|
pub struct Default(Executor);
|
2020-01-20 05:43:09 +01:00
|
|
|
|
2020-02-06 03:56:21 +01:00
|
|
|
impl super::Executor for Default {
|
2020-01-20 05:43:09 +01:00
|
|
|
fn new() -> Result<Self, futures::io::Error> {
|
2020-02-06 03:56:21 +01:00
|
|
|
Ok(Default(Executor::new()?))
|
2020-01-20 05:43:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn spawn(
|
|
|
|
|
&self,
|
|
|
|
|
future: impl futures::Future<Output = ()> + Send + 'static,
|
|
|
|
|
) {
|
2020-02-06 03:56:21 +01:00
|
|
|
let _ = self.0.spawn(future);
|
2020-01-20 05:43:09 +01:00
|
|
|
}
|
2020-02-16 11:40:19 +01:00
|
|
|
|
|
|
|
|
fn enter<R>(&self, f: impl FnOnce() -> R) -> R {
|
2020-11-06 04:20:19 +00:00
|
|
|
super::Executor::enter(&self.0, f)
|
2020-02-16 11:40:19 +01:00
|
|
|
}
|
2020-01-20 05:43:09 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(target_arch = "wasm32")]
|
|
|
|
|
mod platform {
|
2020-02-06 03:56:21 +01:00
|
|
|
use iced_futures::{executor::WasmBindgen, futures, Executor};
|
2020-01-20 05:43:09 +01:00
|
|
|
|
|
|
|
|
/// A default cross-platform executor.
|
|
|
|
|
///
|
2020-03-30 18:18:33 +02:00
|
|
|
/// - 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.
|
2020-01-20 05:43:09 +01:00
|
|
|
/// - On the Web, it will use `iced_futures::executor::WasmBindgen`.
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
pub struct Default(WasmBindgen);
|
|
|
|
|
|
|
|
|
|
impl Executor for Default {
|
|
|
|
|
fn new() -> Result<Self, futures::io::Error> {
|
|
|
|
|
Ok(Default(WasmBindgen::new()?))
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-05 04:14:26 +01:00
|
|
|
fn spawn(&self, future: impl futures::Future<Output = ()> + 'static) {
|
2020-01-20 05:43:09 +01:00
|
|
|
self.0.spawn(future);
|
|
|
|
|
}
|
2020-03-30 18:18:33 +02:00
|
|
|
|
|
|
|
|
fn enter<R>(&self, f: impl FnOnce() -> R) -> R {
|
|
|
|
|
self.0.enter(f)
|
|
|
|
|
}
|
2020-01-20 05:43:09 +01:00
|
|
|
}
|
|
|
|
|
}
|