Skip to content

Commit aa1f5c7

Browse files
authored
Poll Select futures without moving them (#2704)
1 parent 9c6c9a7 commit aa1f5c7

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

futures-util/src/future/select.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,16 @@ where
9999
type Output = Either<(A::Output, B), (B::Output, A)>;
100100

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

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

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

112-
self.inner = Some((a, b));
113112
Poll::Pending
114113
}
115114
}

0 commit comments

Comments
 (0)