MCPcopy Create free account
hub / github.com/TheRedDeveloper/ply-engine / try_recv

Method try_recv

src/net/http.rs:141–168  ·  view source on GitHub ↗

Try to receive a completed response. Returns None if still pending.

(&mut self)

Source from the content-addressed store, hash-verified

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.

Callers 3

poll_completionsFunction · 0.45
cleanMethod · 0.45
responseMethod · 0.45

Calls 2

ply_net_http_try_recvFunction · 0.85
is_emptyMethod · 0.80

Tested by

no test coverage detected