mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-29 00:00:11 +02:00
executor: remove Executor & TypedExecutor traits (#1724)
The `Executor` trait is sub-optimal as it forces a `Box<dyn Future>` to spawn. Instead, `tokio::spawn` delegates to the specific runtime implementation set for the current execution context. `TypedExecutor`, while useful, has seen limited adoption. As such, it is removed from `tokio` proper. Moving it to `tokio-util` is a possibility that can be explored as follow up work.
This commit is contained in:
@@ -1,24 +0,0 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
|
||||
use tokio::executor::DefaultExecutor;
|
||||
|
||||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
|
||||
mod out_of_executor_context {
|
||||
use super::*;
|
||||
use tokio::executor::Executor;
|
||||
|
||||
fn test<F, E>(spawn: F)
|
||||
where
|
||||
F: Fn(Pin<Box<dyn Future<Output = ()> + Send>>) -> Result<(), E>,
|
||||
{
|
||||
let res = spawn(Box::pin(async {}));
|
||||
assert!(res.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn spawn() {
|
||||
test(|f| DefaultExecutor::current().spawn(f));
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
use tokio::executor::{with_default, DefaultExecutor};
|
||||
|
||||
#[test]
|
||||
fn default_executor_is_send_and_sync() {
|
||||
fn assert_send_sync<T: Send + Sync>() {}
|
||||
|
||||
assert_send_sync::<DefaultExecutor>();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn nested_default_executor_status() {
|
||||
let _enter = tokio::executor::enter().unwrap();
|
||||
let mut executor = DefaultExecutor::current();
|
||||
|
||||
let _result = with_default(&mut executor, || ());
|
||||
}
|
||||
Reference in New Issue
Block a user