File tree Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -18,31 +18,36 @@ pin_project! {
1818 stream: S ,
1919 #[ pin]
2020 delay: Timer ,
21+ duration: Duration ,
2122 }
2223}
2324
2425impl < 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
3233impl < 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
You can’t perform that action at this time.
0 commit comments