futures_util/future/
with_executor.rsuse futures_core::{Future, Poll};
use futures_core::task;
use futures_core::executor::Executor;
#[derive(Debug)]
#[must_use = "futures do nothing unless polled"]
pub struct WithExecutor<F, E> where F: Future, E: Executor {
executor: E,
future: F
}
pub fn new<F, E>(future: F, executor: E) -> WithExecutor<F, E>
where F: Future,
E: Executor,
{
WithExecutor { executor, future }
}
impl<F, E> Future for WithExecutor<F, E>
where F: Future,
E: Executor,
{
type Item = F::Item;
type Error = F::Error;
fn poll(&mut self, cx: &mut task::Context) -> Poll<F::Item, F::Error> {
self.future.poll(&mut cx.with_executor(&mut self.executor))
}
}