use std::future::Future;
mod roll;
pub use roll::*;
mod piece;
pub use piece::*;
pub mod bufpool;
use bufpool::*;
mod io;
pub use io::*;
pub mod net;
#[cfg(all(target_os = "linux", feature = "uring"))]
mod uring;
#[cfg(all(target_os = "linux", feature = "uring"))]
pub use uring::get_ring;
pub fn spawn<T: Future + 'static>(task: T) -> tokio::task::JoinHandle<T::Output> {
tokio::task::spawn_local(task)
}
#[cfg(all(target_os = "linux", feature = "uring"))]
pub fn start<F: Future>(task: F) -> F::Output {
use fluke_io_uring_async::IoUringAsync;
use send_wrapper::SendWrapper;
use tokio::task::LocalSet;
let u = SendWrapper::new(uring::get_ring());
let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
.on_thread_park(move || {
u.submit().unwrap();
})
.build()
.unwrap();
let res = rt.block_on(async move {
let local = LocalSet::new();
local.spawn_local(IoUringAsync::listen(get_ring()));
let res = local.run_until(task).await;
if (tokio::time::timeout(std::time::Duration::from_millis(250), local).await).is_err() {
eprintln!("timed out waiting for local set");
}
res
});
rt.shutdown_timeout(std::time::Duration::from_millis(250));
res
}
#[cfg(not(all(target_os = "linux", feature = "uring")))]
pub fn start<F: Future>(task: F) -> F::Output {
use tokio::task::LocalSet;
tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap()
.block_on(async move {
let local = LocalSet::new();
local.run_until(task).await
})
}