mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-24 09:38:29 +02:00
Immediate cancellation
This commit is contained in:
@@ -250,7 +250,7 @@ async fn execute_transaction<R: Runtime>(
|
|||||||
response_id: &String,
|
response_id: &String,
|
||||||
app_handle: &AppHandle<R>,
|
app_handle: &AppHandle<R>,
|
||||||
update_source: &UpdateSource,
|
update_source: &UpdateSource,
|
||||||
cancelled_rx: Receiver<bool>,
|
mut cancelled_rx: Receiver<bool>,
|
||||||
) -> Result<HttpResponse> {
|
) -> Result<HttpResponse> {
|
||||||
let sender = ReqwestSender::with_client(client);
|
let sender = ReqwestSender::with_client(client);
|
||||||
let transaction = HttpTransaction::new(sender);
|
let transaction = HttpTransaction::new(sender);
|
||||||
@@ -338,7 +338,16 @@ async fn execute_transaction<R: Runtime>(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
match body_stream.read(&mut buf).await {
|
// Use select! to race between reading and cancellation, so cancellation is immediate
|
||||||
|
let read_result = tokio::select! {
|
||||||
|
biased;
|
||||||
|
_ = cancelled_rx.changed() => {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
result = body_stream.read(&mut buf) => result,
|
||||||
|
};
|
||||||
|
|
||||||
|
match read_result {
|
||||||
Ok(0) => break, // EOF
|
Ok(0) => break, // EOF
|
||||||
Ok(n) => {
|
Ok(n) => {
|
||||||
file.write_all(&buf[..n])
|
file.write_all(&buf[..n])
|
||||||
|
|||||||
Reference in New Issue
Block a user