veilid/veilid-flutter/rust/src/tools.rs

34 lines
1.1 KiB
Rust
Raw Normal View History

2022-06-29 13:39:54 -04:00
use cfg_if::*;
use core::future::Future;
cfg_if! {
if #[cfg(feature="rt-async-std")] {
pub use async_std::task::JoinHandle;
pub use async_std::net::TcpStream;
2022-07-10 17:36:50 -04:00
//pub use async_std::future::TimeoutError;
2022-06-29 13:39:54 -04:00
pub use async_std::sync::Mutex as AsyncMutex;
pub fn spawn<F: Future<Output = T> + Send + 'static, T: Send + 'static>(f: F) -> JoinHandle<T> {
async_std::task::spawn(f)
}
pub use async_std::task::sleep;
pub use async_std::future::timeout;
} else if #[cfg(feature="rt-tokio")] {
pub use tokio::task::JoinHandle;
pub use tokio::net::TcpStream;
2022-07-10 17:36:50 -04:00
//pub use tokio::time::error::Elapsed as TimeoutError;
2022-06-29 13:39:54 -04:00
pub use tokio::sync::Mutex as AsyncMutex;
pub fn spawn<F: Future<Output = T> + Send + 'static, T: Send + 'static>(f: F) -> JoinHandle<T> {
GLOBAL_RUNTIME.spawn(f)
}
pub use tokio::time::sleep;
pub use tokio::time::timeout;
lazy_static::lazy_static! {
static ref GLOBAL_RUNTIME: tokio::runtime::Runtime = tokio::runtime::Runtime::new().unwrap();
}
}
}