@@ -111,9 +111,9 @@ impl Future for Req {
111
111
//
112
112
113
113
#[ derive( Debug ) ] // !!!! V1
114
- pub struct Progress ( Option < AtomicWaker > , pub Option < AtomicWaker > , pub Option < GcoapMemoState > ) ;
114
+ pub struct Progress < T > ( Option < AtomicWaker > , pub Option < AtomicWaker > , pub Option < T > ) ;
115
115
116
- impl Progress {
116
+ impl < T > Progress < T > {
117
117
pub fn new ( ) -> Self {
118
118
Self ( Some ( AtomicWaker :: new ( ) ) , None , None )
119
119
}
@@ -130,18 +130,24 @@ impl Progress {
130
130
self . 1 . replace ( waker) ;
131
131
}
132
132
133
- pub fn finish ( & mut self , memo : GcoapMemoState ) {
133
+ pub fn resolve ( & mut self , ret : T ) {
134
134
assert ! ( self . 0 . is_none( ) && self . 1 . is_some( ) && self . 2 . is_none( ) ) ; // registered
135
135
136
- self . 2 . replace ( memo ) ;
136
+ self . 2 . replace ( ret ) ;
137
137
self . 1 . take ( ) . unwrap ( ) . wake ( ) ;
138
138
}
139
139
140
+ pub fn take ( & mut self ) -> T {
141
+ assert ! ( self . 0 . is_none( ) && self . 1 . is_none( ) && self . 2 . is_some( ) ) ; // resolved
142
+
143
+ self . 2 . take ( ) . unwrap ( )
144
+ }
145
+
140
146
pub fn as_mut_ptr ( & self ) -> * mut Self {
141
147
self as * const _ as * mut _
142
148
}
143
149
144
- pub fn get_ref_mut ( ptr : * mut Self ) -> & ' static mut Self {
150
+ pub fn get_mut_ref ( ptr : * mut Self ) -> & ' static mut Self {
145
151
unsafe { & mut * ptr }
146
152
}
147
153
}
@@ -155,7 +161,7 @@ pub struct ReqInner {
155
161
blockwise : bool ,
156
162
blockwise_state_index : Option < usize > ,
157
163
blockwise_hdr : Option < heapless:: Vec < u8 , BLOCKWISE_HDR_MAX > > ,
158
- progress : Progress ,
164
+ progress : Progress < GcoapMemoState > ,
159
165
}
160
166
161
167
impl ReqInner {
@@ -177,12 +183,12 @@ impl ReqInner {
177
183
}
178
184
}
179
185
180
- fn gcoap_get ( addr : & str , uri : & str , progress_ptr : * mut Progress ) {
186
+ fn gcoap_get ( addr : & str , uri : & str , progress_ptr : * mut Progress < GcoapMemoState > ) {
181
187
super :: Xbd :: gcoap_req_v2 ( addr, uri, COAP_METHOD_GET , None , false ,
182
188
None , progress_ptr) ;
183
189
}
184
190
185
- fn gcoap_get_blockwise ( addr : & str , uri : & str , blockwise_state_index : usize , progress_ptr : * mut Progress ) {
191
+ fn gcoap_get_blockwise ( addr : & str , uri : & str , blockwise_state_index : usize , progress_ptr : * mut Progress < GcoapMemoState > ) {
186
192
super :: Xbd :: gcoap_req_v2 ( addr, uri, COAP_METHOD_GET , None , true ,
187
193
Some ( blockwise_state_index) , progress_ptr) ;
188
194
}
@@ -239,8 +245,7 @@ impl Future for ReqInner {
239
245
240
246
Poll :: Pending
241
247
} else {
242
- let out = self . progress . 2 . take ( ) . unwrap ( ) ;
243
- Poll :: Ready ( out)
248
+ Poll :: Ready ( self . progress . take ( ) )
244
249
}
245
250
}
246
251
}
0 commit comments