Add some missing future::Executor implementations (#563)

This adds an implementation of future::Executor for
`executor::DefaultExecutor` and `runtime::current_thread::Handle`.
This commit is contained in:
Carl Lerche
2018-09-17 22:23:48 -07:00
committed by GitHub
parent 24dc85dc5e
commit 4019198706
6 changed files with 622 additions and 255 deletions
+20 -1
View File
@@ -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