diff options
Diffstat (limited to 'tokio-executor/src/global.rs')
-rw-r--r-- | tokio-executor/src/global.rs | 33 |
1 files changed, 7 insertions, 26 deletions
diff --git a/tokio-executor/src/global.rs b/tokio-executor/src/global.rs index 1c4c53ff..f2745123 100644 --- a/tokio-executor/src/global.rs +++ b/tokio-executor/src/global.rs @@ -1,6 +1,7 @@ use super::{Enter, Executor, SpawnError}; -use futures::{future, Future}; use std::cell::Cell; +use std::future::Future; +use std::pin::Pin; /// Executes futures on the default executor for the current execution context. /// @@ -70,7 +71,7 @@ thread_local! { impl super::Executor for DefaultExecutor { fn spawn( &mut self, - future: Box<dyn Future<Item = (), Error = ()> + Send>, + future: Pin<Box<dyn Future<Output = ()> + Send>>, ) -> Result<(), SpawnError> { DefaultExecutor::with_current(|executor| executor.spawn(future)) .unwrap_or_else(|| Err(SpawnError::shutdown())) @@ -84,10 +85,10 @@ impl super::Executor for DefaultExecutor { impl<T> super::TypedExecutor<T> for DefaultExecutor where - T: Future<Item = (), Error = ()> + Send + 'static, + T: Future<Output = ()> + Send + 'static, { fn spawn(&mut self, future: T) -> Result<(), SpawnError> { - super::Executor::spawn(self, Box::new(future)) + super::Executor::spawn(self, Box::pin(future)) } fn status(&self) -> Result<(), SpawnError> { @@ -95,26 +96,6 @@ where } } -impl<T> future::Executor<T> for DefaultExecutor -where - T: Future<Item = (), Error = ()> + Send + 'static, -{ - fn execute(&self, future: T) -> Result<(), future::ExecuteError<T>> { - if let Err(e) = super::Executor::status(self) { - let kind = if e.is_at_capacity() { - future::ExecuteErrorKind::NoCapacity - } else { - future::ExecuteErrorKind::Shutdown - }; - - return Err(future::ExecuteError::new(kind, future)); - } - - let _ = DefaultExecutor::with_current(|executor| executor.spawn(Box::new(future))); - Ok(()) - } -} - // ===== global spawn fns ===== /// Submits a future for execution on the default executor -- usually a @@ -153,9 +134,9 @@ where /// ``` pub fn spawn<T>(future: T) where - T: Future<Item = (), Error = ()> + Send + 'static, + T: Future<Output = ()> + Send + 'static, { - DefaultExecutor::current().spawn(Box::new(future)).unwrap() + DefaultExecutor::current().spawn(Box::pin(future)).unwrap() } /// Set the default executor for the duration of the closure |