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

runtime: expose the Runtime structure #88

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
13 changes: 10 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 tokio-uring runtime based on the Tokio current thread runtime.
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() -> io::Result<Runtime> {
/// Create a new tokio-uring [Runtime] object.
pub fn new() -> io::Result<Runtime> {
let rt = tokio::runtime::Builder::new_current_thread()
.on_thread_park(|| {
CURRENT.with(|x| {
Expand All @@ -68,7 +70,12 @@ 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 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<F>(&mut self, future: F) -> F::Output
where
F: Future,
{
Expand Down