use std::future::Future;
pub use compio::net::{TcpListener, TcpStream, ToSocketAddrsAsync as ToSocketAddrs};
pub use compio::time::{sleep, timeout};
pub type OwnedReadHalf = compio::net::OwnedReadHalf<TcpStream>;
pub type OwnedWriteHalf = compio::net::OwnedWriteHalf<TcpStream>;
#[cfg(unix)]
pub use compio::net::{UnixListener, UnixStream};
pub type JoinHandle<T> = compio::runtime::Task<T>;
#[inline]
pub fn spawn<F>(fut: F) -> JoinHandle<F::Output>
where
F: Future + 'static,
{
compio::runtime::spawn(fut)
}
#[inline]
pub fn spawn_detached<F>(fut: F)
where
F: Future + 'static,
F::Output: 'static,
{
compio::runtime::spawn(fut).detach();
}
#[inline]
pub async fn spawn_blocking<F, T>(f: F) -> T
where
F: FnOnce() -> T + Send + Sync + 'static,
T: Send + 'static,
{
compio::runtime::spawn_blocking(f).await
}
#[inline]
pub async fn join<T>(handle: JoinHandle<T>) -> T {
handle.await
}
pub struct LocalRuntime {
inner: compio::runtime::Runtime,
}
impl LocalRuntime {
pub fn new() -> std::io::Result<Self> {
Ok(Self {
inner: compio::runtime::Runtime::new()?,
})
}
pub fn block_on<F: Future>(&self, fut: F) -> F::Output {
self.inner.block_on(fut)
}
}