pub mod pre { pub use futures_lite::{future, stream, Future, FutureExt, Stream, StreamExt}; pub use io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt}; pub use tokio::{fs, io, sync::Notify}; } pub fn Runtime() -> &'static RT { static S: OnceLock = OnceLock::new(); S.get_or_init(|| { RT(rt::Builder::new_multi_thread() .worker_threads(1) .enable_time() .build() .expect("E| Cannot create async runtime")) }) } impl RT { pub fn spawn(&self, future: F) -> Task where F::Output: SendStat, { Task(Some(self.0.spawn(future))) } pub fn finish(&self, mut t: Task) -> T { self.finish_ref(&mut t) } pub fn finish_ref(&self, t: &mut Task) -> T { let t = t.0.take().valid(); self.0.block_on(t).valid() } } pub struct RT(rt::Runtime); pub struct Task(Option>); impl Task { pub fn new_uninit() -> Self { Self(None) } pub fn is_ready(&self) -> bool { self.0.as_ref().map_or(false, |s| s.is_finished()) } } impl Drop for Task { fn drop(&mut self) { if let Some(h) = self.0.take() { h.abort() } } } use {crate::lib::*, pre::*, std::sync::OnceLock, tokio::runtime as rt};