mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-06 00:00:10 +02:00
executor: add TypedExecutor (#993)
Adds a `TypedExecutor` trait that describes how to spawn futures of a specific type. This is useful for implementing functions that are generic over an executor and wish to support both `Send` and `!Send` cases.
This commit is contained in:
+1
-1
@@ -71,7 +71,7 @@ tokio-codec = { version = "0.1.0", optional = true }
|
||||
tokio-current-thread = { version = "0.1.3", optional = true }
|
||||
tokio-fs = { version = "0.1.6", optional = true }
|
||||
tokio-io = { version = "0.1.6", optional = true }
|
||||
tokio-executor = { version = "0.1.5", optional = true }
|
||||
tokio-executor = { version = "0.1.5", optional = true, path = "../tokio-executor" }
|
||||
tokio-reactor = { version = "0.1.1", optional = true }
|
||||
tokio-sync = { version = "0.1.3", optional = true }
|
||||
tokio-threadpool = { version = "0.1.8", optional = true }
|
||||
|
||||
@@ -60,7 +60,7 @@ pub mod thread_pool {
|
||||
};
|
||||
}
|
||||
|
||||
pub use tokio_executor::{Executor, DefaultExecutor, SpawnError};
|
||||
pub use tokio_executor::{Executor, TypedExecutor, DefaultExecutor, SpawnError};
|
||||
|
||||
use futures::{Future, IntoFuture};
|
||||
use futures::future::{self, FutureResult};
|
||||
|
||||
@@ -76,6 +76,15 @@ where T: Future<Item = (), Error = ()> + Send + 'static,
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ::executor::TypedExecutor<T> for Handle
|
||||
where
|
||||
T: Future<Item = (), Error = ()> + Send + 'static,
|
||||
{
|
||||
fn spawn(&mut self, future: T) -> Result<(), ::executor::SpawnError> {
|
||||
Handle::spawn(self, future)
|
||||
}
|
||||
}
|
||||
|
||||
/// Error returned by the `run` function.
|
||||
#[derive(Debug)]
|
||||
pub struct RunError {
|
||||
|
||||
@@ -73,3 +73,12 @@ impl ::executor::Executor for TaskExecutor {
|
||||
self.inner.spawn(future)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ::executor::TypedExecutor<T> for TaskExecutor
|
||||
where
|
||||
T: Future<Item = (), Error = ()> + Send + 'static,
|
||||
{
|
||||
fn spawn(&mut self, future: T) -> Result<(), ::executor::SpawnError> {
|
||||
::executor::Executor::spawn(self, Box::new(future))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user