@@ -54,37 +54,38 @@ impl HttpGetFuture {
54
54
impl Future for HttpGetFuture {
55
55
type Output = String ;
56
56
57
- fn poll ( self : Pin < & mut Self > , waker : & Waker ) -> PollState < Self :: Output > {
57
+ fn poll ( mut self : Pin < & mut Self > , waker : & Waker ) -> PollState < Self :: Output > {
58
58
// If this is first time polled, start the operation
59
59
// see: https://users.rust-lang.org/t/is-it-bad-behaviour-for-a-future-or-stream-to-do-something-before-being-polled/61353
60
60
// Avoid dns lookup this time
61
- let this = self . get_mut ( ) ;
61
+ // let this = self.get_mut();
62
62
63
- if this. stream . is_none ( ) {
63
+ let id = self . id ;
64
+ if self . stream . is_none ( ) {
64
65
println ! ( "FIRST POLL - START OPERATION" ) ;
65
- this . write_request ( ) ;
66
+ self . write_request ( ) ;
66
67
// CHANGED
67
- let stream = this . stream . as_mut ( ) . unwrap ( ) ;
68
- runtime:: reactor ( ) . register ( stream, Interest :: READABLE , this . id ) ;
69
- runtime:: reactor ( ) . set_waker ( waker, this . id ) ;
68
+ let stream = ( & mut self ) . stream . as_mut ( ) . unwrap ( ) ;
69
+ runtime:: reactor ( ) . register ( stream, Interest :: READABLE , id) ;
70
+ runtime:: reactor ( ) . set_waker ( waker, self . id ) ;
70
71
// ============
71
72
}
72
73
73
74
let mut buff = vec ! [ 0u8 ; 147 ] ;
74
75
loop {
75
- match this . stream . as_mut ( ) . unwrap ( ) . read ( & mut buff) {
76
+ match self . stream . as_mut ( ) . unwrap ( ) . read ( & mut buff) {
76
77
Ok ( 0 ) => {
77
- let s = String :: from_utf8_lossy ( & this . buffer ) . to_string ( ) ;
78
- runtime:: reactor ( ) . deregister ( this . stream . as_mut ( ) . unwrap ( ) , this . id ) ;
78
+ let s = String :: from_utf8_lossy ( & self . buffer ) . to_string ( ) ;
79
+ runtime:: reactor ( ) . deregister ( self . stream . as_mut ( ) . unwrap ( ) , id) ;
79
80
break PollState :: Ready ( s. to_string ( ) ) ;
80
81
}
81
82
Ok ( n) => {
82
- this . buffer . extend ( & buff[ 0 ..n] ) ;
83
+ self . buffer . extend ( & buff[ 0 ..n] ) ;
83
84
continue ;
84
85
}
85
86
Err ( e) if e. kind ( ) == ErrorKind :: WouldBlock => {
86
87
// always store the last given Waker
87
- runtime:: reactor ( ) . set_waker ( waker, this . id ) ;
88
+ runtime:: reactor ( ) . set_waker ( waker, self . id ) ;
88
89
break PollState :: NotReady ;
89
90
}
90
91
0 commit comments