Add smol async runtime
This commit is contained in:
parent
92d647d1a6
commit
b2415eee61
8 changed files with 104 additions and 11 deletions
|
|
@ -13,6 +13,9 @@ mod tokio_old;
|
|||
#[cfg(all(not(target_arch = "wasm32"), feature = "async-std"))]
|
||||
mod async_std;
|
||||
|
||||
#[cfg(all(not(target_arch = "wasm32"), feature = "smol"))]
|
||||
mod smol;
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
mod wasm_bindgen;
|
||||
|
||||
|
|
@ -30,6 +33,9 @@ pub use self::tokio_old::TokioOld;
|
|||
#[cfg(all(not(target_arch = "wasm32"), feature = "async-std"))]
|
||||
pub use self::async_std::AsyncStd;
|
||||
|
||||
#[cfg(all(not(target_arch = "wasm32"), feature = "smol"))]
|
||||
pub use self::smol::Smol;
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
pub use wasm_bindgen::WasmBindgen;
|
||||
|
||||
|
|
|
|||
18
futures/src/executor/smol.rs
Normal file
18
futures/src/executor/smol.rs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
use crate::Executor;
|
||||
|
||||
use futures::Future;
|
||||
|
||||
/// A `smol` runtime.
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "smol")))]
|
||||
#[derive(Debug)]
|
||||
pub struct Smol;
|
||||
|
||||
impl Executor for Smol {
|
||||
fn new() -> Result<Self, futures::io::Error> {
|
||||
Ok(Self)
|
||||
}
|
||||
|
||||
fn spawn(&self, future: impl Future<Output = ()> + Send + 'static) {
|
||||
smol::spawn(future).detach();
|
||||
}
|
||||
}
|
||||
|
|
@ -17,10 +17,22 @@ pub mod executor;
|
|||
pub mod subscription;
|
||||
|
||||
#[cfg(all(
|
||||
any(feature = "tokio", feature = "tokio_old", feature = "async-std"),
|
||||
any(
|
||||
feature = "tokio",
|
||||
feature = "tokio_old",
|
||||
feature = "async-std",
|
||||
feature = "smol"
|
||||
),
|
||||
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",
|
||||
feature = "smol"
|
||||
)))
|
||||
)]
|
||||
pub mod time;
|
||||
|
||||
pub use command::Command;
|
||||
|
|
|
|||
|
|
@ -13,6 +13,33 @@ pub fn every<H: std::hash::Hasher, E>(
|
|||
|
||||
struct Every(std::time::Duration);
|
||||
|
||||
#[cfg(all(
|
||||
not(any(feature = "tokio_old", feature = "tokio", feature = "async-std")),
|
||||
feature = "smol"
|
||||
))]
|
||||
impl<H, E> subscription::Recipe<H, E> for Every
|
||||
where
|
||||
H: std::hash::Hasher,
|
||||
{
|
||||
type Output = std::time::Instant;
|
||||
|
||||
fn hash(&self, state: &mut H) {
|
||||
use std::hash::Hash;
|
||||
|
||||
std::any::TypeId::of::<Self>().hash(state);
|
||||
self.0.hash(state);
|
||||
}
|
||||
|
||||
fn stream(
|
||||
self: Box<Self>,
|
||||
_input: futures::stream::BoxStream<'static, E>,
|
||||
) -> futures::stream::BoxStream<'static, Self::Output> {
|
||||
use futures::stream::StreamExt;
|
||||
|
||||
smol::Timer::interval(self.0).boxed()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "async-std")]
|
||||
impl<H, E> subscription::Recipe<H, E> for Every
|
||||
where
|
||||
|
|
@ -41,7 +68,7 @@ where
|
|||
|
||||
#[cfg(all(
|
||||
any(feature = "tokio", feature = "tokio_old"),
|
||||
not(feature = "async-std")
|
||||
not(any(feature = "async-std", feature = "smol"))
|
||||
))]
|
||||
impl<H, E> subscription::Recipe<H, E> for Every
|
||||
where
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue