mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-25 00:00:18 +02:00
Get rid of Enter for with_default (#1315)
We want executors to enforce that there are never multiple active at the same time. This is ensured through `Enter`, which will panic if you attempt to create more than one. However, by requiring you to pass an `&mut Enter` to `executor::with_default`, we were *also* disallowing temporarily overriding the current executor. This patch removes that requirement.
This commit is contained in:
@@ -15,7 +15,6 @@ use std::fmt;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use tokio_executor::park::Park;
|
||||
use tokio_executor::Enter;
|
||||
|
||||
/// Builds a thread pool with custom configuration values.
|
||||
///
|
||||
@@ -261,7 +260,7 @@ impl Builder {
|
||||
/// use tokio_threadpool::Builder;
|
||||
///
|
||||
/// let thread_pool = Builder::new()
|
||||
/// .around_worker(|worker, _| {
|
||||
/// .around_worker(|worker| {
|
||||
/// println!("worker is starting up");
|
||||
/// worker.run();
|
||||
/// println!("worker is shutting down");
|
||||
@@ -272,7 +271,7 @@ impl Builder {
|
||||
/// [`Worker::run`]: struct.Worker.html#method.run
|
||||
pub fn around_worker<F>(&mut self, f: F) -> &mut Self
|
||||
where
|
||||
F: Fn(&Worker, &mut Enter) + Send + Sync + 'static,
|
||||
F: Fn(&Worker) + Send + Sync + 'static,
|
||||
{
|
||||
self.config.around_worker = Some(Callback::new(f));
|
||||
self
|
||||
|
||||
@@ -1,23 +1,22 @@
|
||||
use crate::worker::Worker;
|
||||
use std::fmt;
|
||||
use std::sync::Arc;
|
||||
use tokio_executor::Enter;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct Callback {
|
||||
f: Arc<dyn Fn(&Worker, &mut Enter) + Send + Sync>,
|
||||
f: Arc<dyn Fn(&Worker) + Send + Sync>,
|
||||
}
|
||||
|
||||
impl Callback {
|
||||
pub fn new<F>(f: F) -> Self
|
||||
where
|
||||
F: Fn(&Worker, &mut Enter) + Send + Sync + 'static,
|
||||
F: Fn(&Worker) + Send + Sync + 'static,
|
||||
{
|
||||
Callback { f: Arc::new(f) }
|
||||
}
|
||||
|
||||
pub fn call(&self, worker: &Worker, enter: &mut Enter) {
|
||||
(self.f)(worker, enter)
|
||||
pub fn call(&self, worker: &Worker) {
|
||||
(self.f)(worker)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -119,11 +119,11 @@ impl Worker {
|
||||
let mut sender = Sender { pool };
|
||||
|
||||
// Enter an execution context
|
||||
let mut enter = tokio_executor::enter().unwrap();
|
||||
let _enter = tokio_executor::enter().unwrap();
|
||||
|
||||
tokio_executor::with_default(&mut sender, &mut enter, |enter| {
|
||||
tokio_executor::with_default(&mut sender, || {
|
||||
if let Some(ref callback) = self.pool.config.around_worker {
|
||||
callback.call(self, enter);
|
||||
callback.call(self);
|
||||
} else {
|
||||
self.run();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user