Try to receive a completed response. Returns None if still pending.
(&mut self)
| 139 | |
| 140 | /// Try to receive a completed response. Returns None if still pending. |
| 141 | pub fn try_recv(&mut self) -> Option<Result<Response, String>> { |
| 142 | #[cfg(not(target_arch = "wasm32"))] |
| 143 | { |
| 144 | self.rx.try_recv().ok() |
| 145 | } |
| 146 | |
| 147 | #[cfg(target_arch = "wasm32")] |
| 148 | { |
| 149 | let js_obj = unsafe { ply_net_http_try_recv(self.cid) }; |
| 150 | if js_obj.is_nil() { |
| 151 | return None; |
| 152 | } |
| 153 | |
| 154 | // Check for error field |
| 155 | if js_obj.have_field("error") { |
| 156 | let mut error_str = String::new(); |
| 157 | js_obj.field("error").to_string(&mut error_str); |
| 158 | if !error_str.is_empty() { |
| 159 | return Some(Err(error_str)); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | let status = js_obj.field_u32("status") as u16; |
| 164 | let mut body = Vec::new(); |
| 165 | js_obj.field("body").to_byte_buffer(&mut body); |
| 166 | Some(Ok(Response::new(status, body))) |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | /// Internal state for a tracked HTTP request. |
no test coverage detected