Skip to content

Commit

Permalink
Remove extra SelectAllNext layer
Browse files Browse the repository at this point in the history
No need for this now that `tailcall` is long gone.
  • Loading branch information
alexcrichton committed Oct 13, 2016
1 parent 6520fd5 commit c95e3c4
Showing 1 changed file with 6 additions and 24 deletions.
30 changes: 6 additions & 24 deletions src/select_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,11 @@ use {Future, IntoFuture, Poll, Async};
/// This is created by this `select_all` function.
#[must_use = "futures do nothing unless polled"]
pub struct SelectAll<A> where A: Future {
inner: Vec<SelectAllNext<A>>,
inner: Vec<A>,
}

/// Future yielded as the result in a `SelectAll` future.
///
/// This sentinel future represents the completion of the remaining futures in a
/// list of futures.
#[must_use = "futures do nothing unless polled"]
pub struct SelectAllNext<A> where A: Future {
inner: A,
}
#[doc(hidden)]
pub type SelectAllNext<A> = A;

/// Creates a new future which will select over a list of futures.
///
Expand All @@ -38,7 +32,6 @@ pub fn select_all<I>(iter: I) -> SelectAll<<I::Item as IntoFuture>::Future>
let ret = SelectAll {
inner: iter.into_iter()
.map(|a| a.into_future())
.map(|a| SelectAllNext { inner: a })
.collect(),
};
assert!(ret.inner.len() > 0);
Expand All @@ -48,8 +41,8 @@ pub fn select_all<I>(iter: I) -> SelectAll<<I::Item as IntoFuture>::Future>
impl<A> Future for SelectAll<A>
where A: Future,
{
type Item = (A::Item, usize, Vec<SelectAllNext<A>>);
type Error = (A::Error, usize, Vec<SelectAllNext<A>>);
type Item = (A::Item, usize, Vec<A>);
type Error = (A::Error, usize, Vec<A>);

fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
let item = self.inner.iter_mut().enumerate().filter_map(|(i, f)| {
Expand All @@ -61,7 +54,7 @@ impl<A> Future for SelectAll<A>
}).next();
match item {
Some((idx, res)) => {
drop(self.inner.remove(idx));
self.inner.remove(idx);
let rest = mem::replace(&mut self.inner, Vec::new());
match res {
Ok(e) => Ok(Async::Ready((e, idx, rest))),
Expand All @@ -72,14 +65,3 @@ impl<A> Future for SelectAll<A>
}
}
}

impl<A> Future for SelectAllNext<A>
where A: Future,
{
type Item = A::Item;
type Error = A::Error;

fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
self.inner.poll()
}
}

0 comments on commit c95e3c4

Please sign in to comment.