From 1a9b50e3518ce5cc522dbd7ff22a914c0a346ce3 Mon Sep 17 00:00:00 2001 From: Jiang Liu Date: Tue, 5 Jul 2022 20:31:07 +0800 Subject: [PATCH] runtime: expose the Runtime structure Expose the Runtime structure, so caller could explicitly create a Runtime object and repeatly invokes `block_on()` on it. Signed-off-by: Jiang Liu --- src/lib.rs | 2 +- src/runtime.rs | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 74962405..5d675ead 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -78,7 +78,7 @@ pub mod buf; pub mod fs; pub mod net; -pub use runtime::spawn; +pub use runtime::{spawn, Runtime}; use std::future::Future; diff --git a/src/runtime.rs b/src/runtime.rs index c0b69e75..3d22bf20 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -6,7 +6,8 @@ use std::io; use tokio::io::unix::AsyncFd; use tokio::task::LocalSet; -pub(crate) struct Runtime { +/// The tokio-uring runtime based on the Tokio current thread runtime. +pub struct Runtime { /// io-uring driver driver: AsyncFd, @@ -48,7 +49,8 @@ pub fn spawn(task: T) -> tokio::task::JoinHand } impl Runtime { - pub(crate) fn new() -> io::Result { + /// Create a new tokio-uring [Runtime] object. + pub fn new() -> io::Result { let rt = tokio::runtime::Builder::new_current_thread() .on_thread_park(|| { CURRENT.with(|x| { @@ -68,7 +70,12 @@ impl Runtime { Ok(Runtime { driver, local, rt }) } - pub(crate) fn block_on(&mut self, future: F) -> F::Output + /// Runs a future to completion on the Tokio-uring runtime. + /// + /// This runs the given future on the current thread, blocking until it is + /// complete, and yielding its resolved result. Any tasks or timers + /// which the future spawns internally will be executed on the runtime. + pub fn block_on(&mut self, future: F) -> F::Output where F: Future, {