Skip to content

Commit

Permalink
Poll Select futures without moving them (#2704)
Browse files Browse the repository at this point in the history
  • Loading branch information
EFanZh authored and taiki-e committed Mar 11, 2023
1 parent 7f8442c commit b0d2c56
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions futures-util/src/future/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,16 @@ where
type Output = Either<(A::Output, B), (B::Output, A)>;

fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let (mut a, mut b) = self.inner.take().expect("cannot poll Select twice");
let (a, b) = self.inner.as_mut().expect("cannot poll Select twice");

if let Poll::Ready(val) = a.poll_unpin(cx) {
return Poll::Ready(Either::Left((val, b)));
return Poll::Ready(Either::Left((val, self.inner.take().unwrap().1)));
}

if let Poll::Ready(val) = b.poll_unpin(cx) {
return Poll::Ready(Either::Right((val, a)));
return Poll::Ready(Either::Right((val, self.inner.take().unwrap().0)));
}

self.inner = Some((a, b));
Poll::Pending
}
}
Expand Down

0 comments on commit b0d2c56

Please sign in to comment.