Split iced_futures into different backend implementations
This commit is contained in:
parent
5dab5a327e
commit
167be45a7d
19 changed files with 280 additions and 318 deletions
|
|
@ -1,86 +1,14 @@
|
|||
//! Choose your preferred executor to power your application.
|
||||
pub use crate::runtime::Executor;
|
||||
|
||||
pub use platform::Default;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
mod platform {
|
||||
use iced_futures::{executor, futures};
|
||||
|
||||
#[cfg(feature = "tokio")]
|
||||
type Executor = executor::Tokio;
|
||||
|
||||
#[cfg(all(feature = "async-std", not(feature = "tokio"),))]
|
||||
type Executor = executor::AsyncStd;
|
||||
|
||||
#[cfg(all(
|
||||
feature = "smol",
|
||||
not(any(feature = "tokio", feature = "async-std")),
|
||||
))]
|
||||
type Executor = executor::Smol;
|
||||
|
||||
#[cfg(not(any(
|
||||
feature = "tokio",
|
||||
feature = "async-std",
|
||||
feature = "smol",
|
||||
)))]
|
||||
type Executor = executor::ThreadPool;
|
||||
|
||||
/// A default cross-platform executor.
|
||||
///
|
||||
/// - 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(Executor);
|
||||
|
||||
impl super::Executor for Default {
|
||||
fn new() -> Result<Self, futures::io::Error> {
|
||||
Ok(Default(Executor::new()?))
|
||||
}
|
||||
|
||||
fn spawn(
|
||||
&self,
|
||||
future: impl futures::Future<Output = ()> + Send + 'static,
|
||||
) {
|
||||
let _ = self.0.spawn(future);
|
||||
}
|
||||
|
||||
fn enter<R>(&self, f: impl FnOnce() -> R) -> R {
|
||||
super::Executor::enter(&self.0, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
mod platform {
|
||||
use iced_futures::{executor::WasmBindgen, futures, Executor};
|
||||
|
||||
/// A default cross-platform executor.
|
||||
///
|
||||
/// - 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(WasmBindgen);
|
||||
|
||||
impl Executor for Default {
|
||||
fn new() -> Result<Self, futures::io::Error> {
|
||||
Ok(Default(WasmBindgen::new()?))
|
||||
}
|
||||
|
||||
fn spawn(&self, future: impl futures::Future<Output = ()> + 'static) {
|
||||
self.0.spawn(future);
|
||||
}
|
||||
|
||||
fn enter<R>(&self, f: impl FnOnce() -> R) -> R {
|
||||
self.0.enter(f)
|
||||
}
|
||||
}
|
||||
}
|
||||
/// A default cross-platform executor.
|
||||
///
|
||||
/// - On native platforms, it will use:
|
||||
/// - `iced_futures::backend::native::tokio` when the `tokio` feature is enabled.
|
||||
/// - `iced_futures::backend::native::async-std` when the `async-std` feature is
|
||||
/// enabled.
|
||||
/// - `iced_futures::backend::native::smol` when the `smol` feature is enabled.
|
||||
/// - `iced_futures::backend::native::thread_pool` otherwise.
|
||||
///
|
||||
/// - On Wasm, it will use `iced_futures::backend::wasm::wasm_bindgen`.
|
||||
pub type Default = iced_futures::backend::default::Executor;
|
||||
|
|
|
|||
|
|
@ -156,7 +156,7 @@ impl<T> Application for T
|
|||
where
|
||||
T: Sandbox,
|
||||
{
|
||||
type Executor = crate::runtime::executor::Null;
|
||||
type Executor = iced_futures::backend::null::Executor;
|
||||
type Flags = ();
|
||||
type Message = T::Message;
|
||||
|
||||
|
|
|
|||
12
src/time.rs
12
src/time.rs
|
|
@ -1,12 +1,2 @@
|
|||
//! Listen and react to time.
|
||||
pub use crate::runtime::time::{Duration, Instant};
|
||||
|
||||
use crate::Subscription;
|
||||
|
||||
/// Returns a [`Subscription`] that produces messages at a set interval.
|
||||
///
|
||||
/// The first message is produced after a `duration`, and then continues to
|
||||
/// produce more messages every `duration` after that.
|
||||
pub fn every(duration: Duration) -> Subscription<Instant> {
|
||||
iced_futures::time::every(duration)
|
||||
}
|
||||
pub use iced_futures::backend::default::time::*;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue