monocoque_core/rt/
compio.rs1use std::future::Future;
6
7pub use compio::net::{TcpListener, TcpStream, ToSocketAddrsAsync as ToSocketAddrs};
8pub use compio::time::{sleep, timeout};
9
10pub type OwnedReadHalf = compio::net::OwnedReadHalf<TcpStream>;
12pub type OwnedWriteHalf = compio::net::OwnedWriteHalf<TcpStream>;
14
15#[cfg(unix)]
16pub use compio::net::{UnixListener, UnixStream};
17
18pub type JoinHandle<T> = compio::runtime::Task<T>;
21
22#[inline]
24pub fn spawn<F>(fut: F) -> JoinHandle<F::Output>
25where
26 F: Future + 'static,
27{
28 compio::runtime::spawn(fut)
29}
30
31#[inline]
33pub fn spawn_detached<F>(fut: F)
34where
35 F: Future + 'static,
36 F::Output: 'static,
37{
38 compio::runtime::spawn(fut).detach();
39}
40
41#[inline]
43pub async fn spawn_blocking<F, T>(f: F) -> T
44where
45 F: FnOnce() -> T + Send + Sync + 'static,
46 T: Send + 'static,
47{
48 compio::runtime::spawn_blocking(f).await
49}
50
51#[inline]
56pub async fn join<T>(handle: JoinHandle<T>) -> T {
57 handle.await
58}
59
60pub struct LocalRuntime {
65 inner: compio::runtime::Runtime,
66}
67
68impl LocalRuntime {
69 pub fn new() -> std::io::Result<Self> {
71 Ok(Self {
72 inner: compio::runtime::Runtime::new()?,
73 })
74 }
75
76 pub fn block_on<F: Future>(&self, fut: F) -> F::Output {
78 self.inner.block_on(fut)
79 }
80}