Skip to content
Open
Changes from 2 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
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ use std::thread;
use futures_core::ready;
use once_cell::sync::Lazy;
use pin_project_lite::pin_project;
use tokio::runtime::EnterGuard;

/// Applies the [`Compat`] adapter to futures and I/O types.
pub trait CompatExt {
Expand Down Expand Up @@ -453,6 +454,17 @@ impl<T: futures_io::AsyncSeek> tokio::io::AsyncSeek for Compat<T> {
}
}

/// Manually enter the tokio runtime.
///
/// This function returns the [`EnterGuard`] which keeps the tokio runtime active until it is
/// dropped. Use this function when you cannot use one of the preexisting wrappers this crate
/// provides.
///
/// TODO: Examples
pub fn enter_tokio_runtime() -> EnterGuard<'static> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make this wrap a newtype around EnterGuard, I don't want to directly expose the tokio dependency.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that the way entering tokio runtimes works has been changed. Would it be better if this public function entered the runtime for you or would it be better to make a wrapper of get_runtime_handle which returns a newtype and requires the user to call enter on it?

TOKIO1.handle.enter()
}

static TOKIO1: Lazy<GlobalRuntime> = Lazy::new(|| {
let mut fallback_rt = None;
let handle = tokio::runtime::Handle::try_current().unwrap_or_else(|_| {
Expand Down
Loading