add ability to synchronize in tests

- Adds `wait_for` that takes another future to signal the mock
  should continue.
- Adds `yield_once` to allow one chain of futures to yield to the
  other.
This commit is contained in:
Sean McArthur
2018-03-29 13:29:41 -07:00
parent 1c5d4ded50
commit 65f69a3062
3 changed files with 52 additions and 14 deletions

View File

@@ -477,6 +477,16 @@ pub trait HandleFutureExt {
}))
}
fn wait_for<F>(self, other: F) -> Box<Future<Item = Self::Item, Error = Self::Error>>
where
F: Future + 'static,
Self: Future + Sized + 'static
{
Box::new(self.then(move |result| {
other.then(move |_| result)
}))
}
fn close(self) -> Box<Future<Item = (), Error = ()>>
where
Self: Future<Error = ()> + Sized + 'static,