@@ -8,6 +8,7 @@ use crate::http::response::try_from_incoming;
8
8
use crate :: io:: { self , AsyncOutputStream , AsyncPollable } ;
9
9
use crate :: runtime:: WaitFor ;
10
10
use crate :: time:: Duration ;
11
+ use pin_project_lite:: pin_project;
11
12
use std:: future:: Future ;
12
13
use std:: pin:: Pin ;
13
14
use std:: task:: { Context , Poll } ;
@@ -83,24 +84,35 @@ impl Client {
83
84
84
85
let outgoing_body = OutgoingBody :: new ( AsyncOutputStream :: new ( wasi_stream) , wasi_body) ;
85
86
86
- struct IncomingResponseFuture {
87
- subscription : WaitFor ,
88
- wasi : WasiFutureIncomingResponse ,
87
+ pin_project ! {
88
+ struct IncomingResponseFuture {
89
+ #[ pin]
90
+ subscription: Option <WaitFor >,
91
+ wasi: WasiFutureIncomingResponse ,
92
+ }
89
93
}
90
94
impl Future for IncomingResponseFuture {
91
95
type Output = Result < Response < IncomingBody > > ;
92
96
93
97
fn poll ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Self :: Output > {
94
- match pin_project ( self . subscription ) . poll ( cx) {
98
+ let this = self . project ( ) ;
99
+ match this. subscription . as_pin_mut ( ) . expect ( "make it so" ) . poll ( cx) {
95
100
Poll :: Pending => Poll :: Pending ,
96
- Poll :: Ready ( response) => Poll :: Ready ( try_from_incoming ( response) ) ,
101
+ Poll :: Ready ( ( ) ) => Poll :: Ready (
102
+ this. wasi
103
+ . get ( )
104
+ . unwrap ( )
105
+ . unwrap ( )
106
+ . map_err ( Error :: from)
107
+ . and_then ( try_from_incoming) ,
108
+ ) ,
97
109
}
98
110
}
99
111
}
100
112
101
113
let subscription = AsyncPollable :: new ( res. subscribe ( ) ) . wait_for ( ) ;
102
114
let future = IncomingResponseFuture {
103
- subscription,
115
+ subscription : Some ( subscription ) ,
104
116
wasi : res,
105
117
} ;
106
118
0 commit comments