Introduce `tokio_old` feature
This feature allows users to rely on the `0.2` version of `tokio` while the async ecosystem upgrades to the latest version.
This commit is contained in:
parent
a4ad1b297e
commit
782dd2f522
|
@ -33,6 +33,8 @@ glow_default_system_font = ["iced_glow/default_system_font"]
|
||||||
debug = ["iced_winit/debug"]
|
debug = ["iced_winit/debug"]
|
||||||
# Enables `tokio` as the `executor::Default` on native platforms
|
# Enables `tokio` as the `executor::Default` on native platforms
|
||||||
tokio = ["iced_futures/tokio"]
|
tokio = ["iced_futures/tokio"]
|
||||||
|
# Enables old `tokio` (0.2) as the `executor::Default` on native platforms
|
||||||
|
tokio_old = ["iced_futures/tokio_old"]
|
||||||
# Enables `async-std` as the `executor::Default` on native platforms
|
# Enables `async-std` as the `executor::Default` on native platforms
|
||||||
async-std = ["iced_futures/async-std"]
|
async-std = ["iced_futures/async-std"]
|
||||||
# Enables advanced color conversion via `palette`
|
# Enables advanced color conversion via `palette`
|
||||||
|
|
|
@ -6,7 +6,7 @@ edition = "2018"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
iced = { path = "../..", features = ["tokio"] }
|
iced = { path = "../..", features = ["tokio_old"] }
|
||||||
iced_native = { path = "../../native" }
|
iced_native = { path = "../../native" }
|
||||||
iced_futures = { path = "../../futures" }
|
iced_futures = { path = "../../futures" }
|
||||||
reqwest = "0.10"
|
reqwest = "0.10"
|
||||||
|
|
|
@ -6,7 +6,7 @@ edition = "2018"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
iced = { path = "../..", features = ["image", "debug", "tokio"] }
|
iced = { path = "../..", features = ["image", "debug", "tokio_old"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
|
|
||||||
[dependencies.serde]
|
[dependencies.serde]
|
||||||
|
|
|
@ -19,6 +19,12 @@ log = "0.4"
|
||||||
[dependencies.futures]
|
[dependencies.futures]
|
||||||
version = "0.3"
|
version = "0.3"
|
||||||
|
|
||||||
|
[target.'cfg(not(target_arch = "wasm32"))'.dependencies.tokio_old]
|
||||||
|
package = "tokio"
|
||||||
|
version = "0.2"
|
||||||
|
optional = true
|
||||||
|
features = ["rt-core", "rt-threaded", "time", "stream"]
|
||||||
|
|
||||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies.tokio]
|
[target.'cfg(not(target_arch = "wasm32"))'.dependencies.tokio]
|
||||||
version = "0.3"
|
version = "0.3"
|
||||||
optional = true
|
optional = true
|
||||||
|
|
|
@ -7,6 +7,9 @@ mod thread_pool;
|
||||||
#[cfg(all(not(target_arch = "wasm32"), feature = "tokio"))]
|
#[cfg(all(not(target_arch = "wasm32"), feature = "tokio"))]
|
||||||
mod tokio;
|
mod tokio;
|
||||||
|
|
||||||
|
#[cfg(all(not(target_arch = "wasm32"), feature = "tokio_old"))]
|
||||||
|
mod tokio_old;
|
||||||
|
|
||||||
#[cfg(all(not(target_arch = "wasm32"), feature = "async-std"))]
|
#[cfg(all(not(target_arch = "wasm32"), feature = "async-std"))]
|
||||||
mod async_std;
|
mod async_std;
|
||||||
|
|
||||||
|
@ -21,6 +24,9 @@ pub use thread_pool::ThreadPool;
|
||||||
#[cfg(all(not(target_arch = "wasm32"), feature = "tokio"))]
|
#[cfg(all(not(target_arch = "wasm32"), feature = "tokio"))]
|
||||||
pub use self::tokio::Tokio;
|
pub use self::tokio::Tokio;
|
||||||
|
|
||||||
|
#[cfg(all(not(target_arch = "wasm32"), feature = "tokio_old"))]
|
||||||
|
pub use self::tokio_old::TokioOld;
|
||||||
|
|
||||||
#[cfg(all(not(target_arch = "wasm32"), feature = "async-std"))]
|
#[cfg(all(not(target_arch = "wasm32"), feature = "async-std"))]
|
||||||
pub use self::async_std::AsyncStd;
|
pub use self::async_std::AsyncStd;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
use crate::Executor;
|
||||||
|
|
||||||
|
use futures::Future;
|
||||||
|
|
||||||
|
/// An old `tokio` runtime.
|
||||||
|
#[cfg_attr(docsrs, doc(cfg(feature = "tokio_old")))]
|
||||||
|
pub type TokioOld = tokio_old::runtime::Runtime;
|
||||||
|
|
||||||
|
impl Executor for TokioOld {
|
||||||
|
fn new() -> Result<Self, futures::io::Error> {
|
||||||
|
tokio_old::runtime::Runtime::new()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn spawn(&self, future: impl Future<Output = ()> + Send + 'static) {
|
||||||
|
let _ = tokio_old::runtime::Runtime::spawn(self, future);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn enter<R>(&self, f: impl FnOnce() -> R) -> R {
|
||||||
|
tokio_old::runtime::Runtime::enter(self, f)
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,7 +15,7 @@ pub mod executor;
|
||||||
pub mod subscription;
|
pub mod subscription;
|
||||||
|
|
||||||
#[cfg(all(
|
#[cfg(all(
|
||||||
any(feature = "tokio", feature = "async-std"),
|
any(feature = "tokio", feature = "tokio_old", feature = "async-std"),
|
||||||
not(target_arch = "wasm32")
|
not(target_arch = "wasm32")
|
||||||
))]
|
))]
|
||||||
#[cfg_attr(docsrs, doc(cfg(any(feature = "tokio", feature = "async-std"))))]
|
#[cfg_attr(docsrs, doc(cfg(any(feature = "tokio", feature = "async-std"))))]
|
||||||
|
|
|
@ -41,7 +41,10 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(feature = "tokio", not(feature = "async-std")))]
|
#[cfg(all(
|
||||||
|
any(feature = "tokio", feature = "tokio_old"),
|
||||||
|
not(feature = "async-std")
|
||||||
|
))]
|
||||||
impl<H, E> subscription::Recipe<H, E> for Every
|
impl<H, E> subscription::Recipe<H, E> for Every
|
||||||
where
|
where
|
||||||
H: std::hash::Hasher,
|
H: std::hash::Hasher,
|
||||||
|
@ -61,6 +64,9 @@ where
|
||||||
) -> futures::stream::BoxStream<'static, Self::Output> {
|
) -> futures::stream::BoxStream<'static, Self::Output> {
|
||||||
use futures::stream::StreamExt;
|
use futures::stream::StreamExt;
|
||||||
|
|
||||||
|
#[cfg(feature = "tokio_old")]
|
||||||
|
use tokio_old as tokio;
|
||||||
|
|
||||||
let start = tokio::time::Instant::now() + self.0;
|
let start = tokio::time::Instant::now() + self.0;
|
||||||
|
|
||||||
tokio::time::interval_at(start, self.0)
|
tokio::time::interval_at(start, self.0)
|
||||||
|
|
|
@ -7,13 +7,23 @@ pub use platform::Default;
|
||||||
mod platform {
|
mod platform {
|
||||||
use iced_futures::{executor, futures};
|
use iced_futures::{executor, futures};
|
||||||
|
|
||||||
#[cfg(feature = "tokio")]
|
#[cfg(feature = "tokio_old")]
|
||||||
|
type Executor = executor::TokioOld;
|
||||||
|
|
||||||
|
#[cfg(all(not(feature = "tokio_old"), feature = "tokio"))]
|
||||||
type Executor = executor::Tokio;
|
type Executor = executor::Tokio;
|
||||||
|
|
||||||
#[cfg(all(not(feature = "tokio"), feature = "async-std"))]
|
#[cfg(all(
|
||||||
|
not(any(feature = "tokio_old", feature = "tokio")),
|
||||||
|
feature = "async-std"
|
||||||
|
))]
|
||||||
type Executor = executor::AsyncStd;
|
type Executor = executor::AsyncStd;
|
||||||
|
|
||||||
#[cfg(not(any(feature = "tokio", feature = "async-std")))]
|
#[cfg(not(any(
|
||||||
|
feature = "tokio_old",
|
||||||
|
feature = "tokio",
|
||||||
|
feature = "async-std"
|
||||||
|
)))]
|
||||||
type Executor = executor::ThreadPool;
|
type Executor = executor::ThreadPool;
|
||||||
|
|
||||||
/// A default cross-platform executor.
|
/// A default cross-platform executor.
|
||||||
|
|
11
src/lib.rs
11
src/lib.rs
|
@ -193,10 +193,17 @@ pub mod widget;
|
||||||
pub mod window;
|
pub mod window;
|
||||||
|
|
||||||
#[cfg(all(
|
#[cfg(all(
|
||||||
any(feature = "tokio", feature = "async-std"),
|
any(feature = "tokio", feature = "tokio_old", feature = "async-std"),
|
||||||
not(target_arch = "wasm32")
|
not(target_arch = "wasm32")
|
||||||
))]
|
))]
|
||||||
#[cfg_attr(docsrs, doc(cfg(any(feature = "tokio", feature = "async-std"))))]
|
#[cfg_attr(
|
||||||
|
docsrs,
|
||||||
|
doc(cfg(any(
|
||||||
|
feature = "tokio",
|
||||||
|
feature = "tokio_old",
|
||||||
|
feature = "async-std"
|
||||||
|
)))
|
||||||
|
)]
|
||||||
pub mod time;
|
pub mod time;
|
||||||
|
|
||||||
#[cfg(all(
|
#[cfg(all(
|
||||||
|
|
Loading…
Reference in New Issue