diff options
author | Carl Lerche <me@carllerche.com> | 2018-09-17 22:23:48 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-17 22:23:48 -0700 |
commit | 4019198706604b107b433499db59d91894aa676e (patch) | |
tree | 8eddb76011bf09fcab0428d330faabe4dd88a482 /tokio-executor/src | |
parent | 24dc85dc5e71526aa74b5587348c973beab7ac47 (diff) |
Add some missing future::Executor implementations (#563)
This adds an implementation of future::Executor for
`executor::DefaultExecutor` and `runtime::current_thread::Handle`.
Diffstat (limited to 'tokio-executor/src')
-rw-r--r-- | tokio-executor/src/global.rs | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/tokio-executor/src/global.rs b/tokio-executor/src/global.rs index 24867cd5..1420deaf 100644 --- a/tokio-executor/src/global.rs +++ b/tokio-executor/src/global.rs @@ -1,6 +1,6 @@ use super::{Executor, Enter, SpawnError}; -use futures::Future; +use futures::{future, Future}; use std::cell::Cell; @@ -83,6 +83,25 @@ impl super::Executor for DefaultExecutor { } } +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 |