Skip to main content

dope_runtime/
lib.rs

1use std::future::Future;
2use std::time::Duration;
3
4pub mod executor;
5pub mod launcher;
6pub mod runtime;
7mod sys;
8pub mod time;
9
10cfg_select! {
11    target_os = "linux" => {
12        pub type DefaultBackend = dope_uring::UringBackend;
13    }
14    _ => {
15        pub type DefaultBackend = dope_kqueue::KqueueBackend;
16    }
17}
18
19pub type Driver = <DefaultBackend as dope_core::driver::Backend>::Driver;
20pub type RuntimeCtx = executor::RuntimeCtx<DefaultBackend>;
21pub type ExternalDispatch = dope_core::driver::ExternalDispatch<DefaultBackend>;
22pub type JoinHandle<T> = executor::JoinHandle<T>;
23
24#[inline(always)]
25pub fn current() -> RuntimeCtx {
26    executor::current::<DefaultBackend>()
27}
28
29#[inline(always)]
30pub fn spawn<F>(fut: F) -> JoinHandle<F::Output>
31where
32    F: Future + 'static,
33    F::Output: 'static,
34{
35    executor::spawn::<DefaultBackend, F>(fut)
36}
37
38#[inline(always)]
39pub fn block_on<F: Future>(fut: F) -> F::Output {
40    executor::block_on::<DefaultBackend, F>(fut)
41}
42
43#[inline(always)]
44pub fn install_external(aux: Option<ExternalDispatch>) -> Option<ExternalDispatch> {
45    executor::install_external::<DefaultBackend>(aux)
46}
47
48#[inline(always)]
49pub async fn sleep(duration: Duration) -> std::io::Result<()> {
50    time::sleep::<DefaultBackend>(duration).await
51}
52
53#[inline(always)]
54pub fn timeout<F: Future>(
55    duration: Duration,
56    fut: F,
57) -> impl Future<Output = std::io::Result<F::Output>> {
58    time::timeout::<DefaultBackend, F>(duration, fut)
59}