Skip to content

Commit 3bb121d

Browse files
author
hhggit
committed
reset timer after timeout was ready
1 parent 7303500 commit 3bb121d

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

Diff for: src/stream/stream/timeout.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,36 @@ pin_project! {
1818
stream: S,
1919
#[pin]
2020
delay: Timer,
21+
duration: Duration,
2122
}
2223
}
2324

2425
impl<S: Stream> Timeout<S> {
2526
pub(crate) fn new(stream: S, dur: Duration) -> Self {
2627
let delay = timer_after(dur);
2728

28-
Self { stream, delay }
29+
Self { stream, delay, duration: dur }
2930
}
3031
}
3132

3233
impl<S: Stream> Stream for Timeout<S> {
3334
type Item = Result<S::Item, TimeoutError>;
3435

3536
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
36-
let this = self.project();
37+
let mut this = self.project();
3738

38-
match this.stream.poll_next(cx) {
39+
let r = match this.stream.poll_next(cx) {
3940
Poll::Ready(Some(v)) => Poll::Ready(Some(Ok(v))),
4041
Poll::Ready(None) => Poll::Ready(None),
41-
Poll::Pending => match this.delay.poll(cx) {
42+
Poll::Pending => match this.delay.as_mut().poll(cx) {
4243
Poll::Ready(_) => Poll::Ready(Some(Err(TimeoutError { _private: () }))),
43-
Poll::Pending => Poll::Pending,
44+
Poll::Pending => return Poll::Pending,
4445
},
45-
}
46+
};
47+
48+
*this.delay.as_mut() = timer_after(*this.duration);
49+
50+
r
4651
}
4752
}
4853

0 commit comments

Comments
 (0)