Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose runtime structure #148

Merged
merged 2 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ pub mod fs;
pub mod net;

pub use runtime::spawn;
pub use runtime::Runtime;

use std::future::Future;

Expand Down Expand Up @@ -140,7 +141,7 @@ use std::future::Future;
/// }
/// ```
pub fn start<F: Future>(future: F) -> F::Output {
let mut rt = runtime::Runtime::new(&builder()).unwrap();
let rt = runtime::Runtime::new(&builder()).unwrap();
rt.block_on(future)
}

Expand Down Expand Up @@ -225,7 +226,7 @@ impl Builder {
/// }
/// ```
pub fn start<F: Future>(&self, future: F) -> F::Output {
let mut rt = runtime::Runtime::new(self).unwrap();
let rt = runtime::Runtime::new(self).unwrap();
rt.block_on(future)
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use std::io;
use tokio::io::unix::AsyncFd;
use tokio::task::LocalSet;

pub(crate) struct Runtime {
/// The Runtime executor
pub struct Runtime {
/// io-uring driver
driver: AsyncFd<Driver>,

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

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

pub(crate) fn block_on<F>(&mut self, future: F) -> F::Output
/// Runs a future to completion on the current runtime
pub fn block_on<F>(&self, future: F) -> F::Output
where
F: Future,
{
Expand Down