Skip to content

Commit cb189fa

Browse files
ollie-etlollie-etl
andauthored
Expose runtime structure (tokio-rs#148)
Co-authored-by: ollie-etl <Oliver [email protected]>
1 parent 2297ed7 commit cb189fa

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ pub mod fs;
7979
pub mod net;
8080

8181
pub use runtime::spawn;
82+
pub use runtime::Runtime;
8283

8384
use std::future::Future;
8485

@@ -140,7 +141,7 @@ use std::future::Future;
140141
/// }
141142
/// ```
142143
pub fn start<F: Future>(future: F) -> F::Output {
143-
let mut rt = runtime::Runtime::new(&builder()).unwrap();
144+
let rt = runtime::Runtime::new(&builder()).unwrap();
144145
rt.block_on(future)
145146
}
146147

@@ -225,7 +226,7 @@ impl Builder {
225226
/// }
226227
/// ```
227228
pub fn start<F: Future>(&self, future: F) -> F::Output {
228-
let mut rt = runtime::Runtime::new(self).unwrap();
229+
let rt = runtime::Runtime::new(self).unwrap();
229230
rt.block_on(future)
230231
}
231232
}

src/runtime.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ use std::io;
66
use tokio::io::unix::AsyncFd;
77
use tokio::task::LocalSet;
88

9-
pub(crate) struct Runtime {
9+
/// The Runtime executor
10+
pub struct Runtime {
1011
/// io-uring driver
1112
driver: AsyncFd<Driver>,
1213

@@ -48,7 +49,8 @@ pub fn spawn<T: std::future::Future + 'static>(task: T) -> tokio::task::JoinHand
4849
}
4950

5051
impl Runtime {
51-
pub(crate) fn new(b: &crate::Builder) -> io::Result<Runtime> {
52+
/// Create a new tokio_uring runtime on the current thread
53+
pub fn new(b: &crate::Builder) -> io::Result<Runtime> {
5254
let rt = tokio::runtime::Builder::new_current_thread()
5355
.on_thread_park(|| {
5456
CURRENT.with(|x| {
@@ -68,7 +70,8 @@ impl Runtime {
6870
Ok(Runtime { driver, local, rt })
6971
}
7072

71-
pub(crate) fn block_on<F>(&mut self, future: F) -> F::Output
73+
/// Runs a future to completion on the current runtime
74+
pub fn block_on<F>(&self, future: F) -> F::Output
7275
where
7376
F: Future,
7477
{

0 commit comments

Comments
 (0)