File tree 1 file changed +11
-6
lines changed
1 file changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -18,31 +18,36 @@ pin_project! {
18
18
stream: S ,
19
19
#[ pin]
20
20
delay: Timer ,
21
+ duration: Duration ,
21
22
}
22
23
}
23
24
24
25
impl < S : Stream > Timeout < S > {
25
26
pub ( crate ) fn new ( stream : S , dur : Duration ) -> Self {
26
27
let delay = timer_after ( dur) ;
27
28
28
- Self { stream, delay }
29
+ Self { stream, delay, duration : dur }
29
30
}
30
31
}
31
32
32
33
impl < S : Stream > Stream for Timeout < S > {
33
34
type Item = Result < S :: Item , TimeoutError > ;
34
35
35
36
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 ( ) ;
37
38
38
- match this. stream . poll_next ( cx) {
39
+ let r = match this. stream . poll_next ( cx) {
39
40
Poll :: Ready ( Some ( v) ) => Poll :: Ready ( Some ( Ok ( v) ) ) ,
40
41
Poll :: Ready ( None ) => Poll :: Ready ( None ) ,
41
- Poll :: Pending => match this. delay . poll ( cx) {
42
+ Poll :: Pending => match this. delay . as_mut ( ) . poll ( cx) {
42
43
Poll :: Ready ( _) => Poll :: Ready ( Some ( Err ( TimeoutError { _private : ( ) } ) ) ) ,
43
- Poll :: Pending => Poll :: Pending ,
44
+ Poll :: Pending => return Poll :: Pending ,
44
45
} ,
45
- }
46
+ } ;
47
+
48
+ * this. delay . as_mut ( ) = timer_after ( * this. duration ) ;
49
+
50
+ r
46
51
}
47
52
}
48
53
You can’t perform that action at this time.
0 commit comments