either_future/
futures01.rs1#![cfg(feature = "futures01")]
2extern crate either;
3extern crate futures;
4
5use self::either::Either;
6use self::futures::Async;
7use super::EitherFuture;
8
9impl<Left, Right, ErrorType, LeftFuture, RightFuture> futures::Future for EitherFuture<LeftFuture, RightFuture>
10where
11 LeftFuture: futures::Future<Item = Left, Error = ErrorType>,
12 RightFuture: futures::Future<Item = Right, Error = ErrorType>,
13{
14 type Item = Either<Left, Right>;
15 type Error = ErrorType;
16
17 fn poll(&mut self) -> Result<Async<Self::Item>, Self::Error> {
18 let either = match self.0.as_mut() {
19 Either::Left(left_future) => match left_future.poll()? {
20 Async::Ready(left) => Either::Left(left),
21 Async::NotReady => return Ok(Async::NotReady),
22 },
23 Either::Right(right_future) => match right_future.poll()? {
24 Async::Ready(right) => Either::Right(right),
25 Async::NotReady => return Ok(Async::NotReady),
26 },
27 };
28 Ok(Async::Ready(either))
29 }
30}