mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-10-01 12:20:39 +00:00
Add a verbose error message for EnterError (#441)
Add a verbose error message for EnterError while trying to run an executor while another executor is already running. Fixes: #410
This commit is contained in:
parent
ecfe2f6a05
commit
7153d8d6ce
@ -250,14 +250,16 @@ impl<P: Park> CurrentThread<P> {
|
|||||||
-> Result<F::Item, BlockError<F::Error>>
|
-> Result<F::Item, BlockError<F::Error>>
|
||||||
where F: Future
|
where F: Future
|
||||||
{
|
{
|
||||||
let mut enter = tokio_executor::enter().unwrap();
|
let mut enter = tokio_executor::enter()
|
||||||
|
.expect("failed to start `current_thread::Runtime`");
|
||||||
self.enter(&mut enter).block_on(future)
|
self.enter(&mut enter).block_on(future)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Run the executor to completion, blocking the thread until **all**
|
/// Run the executor to completion, blocking the thread until **all**
|
||||||
/// spawned futures have completed.
|
/// spawned futures have completed.
|
||||||
pub fn run(&mut self) -> Result<(), RunError> {
|
pub fn run(&mut self) -> Result<(), RunError> {
|
||||||
let mut enter = tokio_executor::enter().unwrap();
|
let mut enter = tokio_executor::enter()
|
||||||
|
.expect("failed to start `current_thread::Runtime`");
|
||||||
self.enter(&mut enter).run()
|
self.enter(&mut enter).run()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,7 +268,8 @@ impl<P: Park> CurrentThread<P> {
|
|||||||
pub fn run_timeout(&mut self, duration: Duration)
|
pub fn run_timeout(&mut self, duration: Duration)
|
||||||
-> Result<(), RunTimeoutError>
|
-> Result<(), RunTimeoutError>
|
||||||
{
|
{
|
||||||
let mut enter = tokio_executor::enter().unwrap();
|
let mut enter = tokio_executor::enter()
|
||||||
|
.expect("failed to start `current_thread::Runtime`");
|
||||||
self.enter(&mut enter).run_timeout(duration)
|
self.enter(&mut enter).run_timeout(duration)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,7 +279,8 @@ impl<P: Park> CurrentThread<P> {
|
|||||||
pub fn turn(&mut self, duration: Option<Duration>)
|
pub fn turn(&mut self, duration: Option<Duration>)
|
||||||
-> Result<Turn, TurnError>
|
-> Result<Turn, TurnError>
|
||||||
{
|
{
|
||||||
let mut enter = tokio_executor::enter().unwrap();
|
let mut enter = tokio_executor::enter()
|
||||||
|
.expect("failed to start `current_thread::Runtime`");
|
||||||
self.enter(&mut enter).turn(duration)
|
self.enter(&mut enter).turn(duration)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,11 +20,18 @@ pub struct Enter {
|
|||||||
|
|
||||||
/// An error returned by `enter` if an execution scope has already been
|
/// An error returned by `enter` if an execution scope has already been
|
||||||
/// entered.
|
/// entered.
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct EnterError {
|
pub struct EnterError {
|
||||||
_a: (),
|
_a: (),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Debug for EnterError {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
f.debug_struct("EnterError")
|
||||||
|
.field("reason", &"attempted to run an executor while another executor is already running")
|
||||||
|
.finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Marks the current thread as being within the dynamic extent of an
|
/// Marks the current thread as being within the dynamic extent of an
|
||||||
/// executor.
|
/// executor.
|
||||||
///
|
///
|
||||||
|
Loading…
x
Reference in New Issue
Block a user