Spawn an HTTP request on the Tokio runtime and return a receiver for the result. This allows GPUI's async executor to await the result without being in a Tokio context.
(
&self,
method: HttpMethod,
url: String,
headers: Vec<Header>,
body: RequestBody,
)
| 44 | /// Spawn an HTTP request on the Tokio runtime and return a receiver for the result. |
| 45 | /// This allows GPUI's async executor to await the result without being in a Tokio context. |
| 46 | pub fn spawn_request( |
| 47 | &self, |
| 48 | method: HttpMethod, |
| 49 | url: String, |
| 50 | headers: Vec<Header>, |
| 51 | body: RequestBody, |
| 52 | ) -> (oneshot::Receiver<Result<ResponseData>>, InFlightRequest) { |
| 53 | let (tx, rx) = oneshot::channel(); |
| 54 | let client = self.client.clone(); |
| 55 | |
| 56 | let task = self.runtime.spawn(async move { |
| 57 | let result = execute_request(client, method, url, headers, body).await; |
| 58 | let _ = tx.send(result); |
| 59 | }); |
| 60 | |
| 61 | (rx, InFlightRequest { task: Some(task) }) |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | /// Internal function to execute the HTTP request |
no test coverage detected