mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-27 00:00:12 +02:00
Make tokio::run panic if called from inside tokio::run (#646)
This is implemented by creating an `Enter` instance from within `run`. This patch also introduces `Enter::block_on`. Fixes #504
This commit is contained in:
committed by
Carl Lerche
parent
85f8522536
commit
98d23b8b29
@@ -3,6 +3,8 @@ use std::cell::Cell;
|
||||
use std::error::Error;
|
||||
use std::fmt;
|
||||
|
||||
use futures::{self, Future};
|
||||
|
||||
thread_local!(static ENTERED: Cell<bool> = Cell::new(false));
|
||||
|
||||
/// Represents an executor context.
|
||||
@@ -80,6 +82,13 @@ impl Enter {
|
||||
pub fn make_permanent(mut self) {
|
||||
self.permanent = true;
|
||||
}
|
||||
|
||||
/// Blocks the thread on the specified future, returning the value with
|
||||
/// which that future completes.
|
||||
pub fn block_on<F: Future>(&mut self, f: F) -> Result<F::Item, F::Error> {
|
||||
futures::executor::spawn(f).wait_future()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl fmt::Debug for Enter {
|
||||
|
||||
Reference in New Issue
Block a user