nxtquic_api/runtime/
mod.rs1pub mod driver;
4
5pub use driver::EndpointDriver;
6use std::future::Future;
7use std::pin::Pin;
8use std::time::Duration;
9
10pub trait Runtime: Send + Sync + 'static {
12 fn spawn(&self, future: Pin<Box<dyn Future<Output = ()> + Send>>);
14
15 fn sleep(&self, duration: Duration) -> Pin<Box<dyn Future<Output = ()> + Send>>;
17}
18
19#[derive(Clone, Copy, Debug, Default)]
21pub struct TokioRuntime;
22
23impl Runtime for TokioRuntime {
24 fn spawn(&self, future: Pin<Box<dyn Future<Output = ()> + Send>>) {
25 tokio::spawn(future);
26 }
27
28 fn sleep(&self, duration: Duration) -> Pin<Box<dyn Future<Output = ()> + Send>> {
29 Box::pin(tokio::time::sleep(duration))
30 }
31}