From 568b2fbd70a9f64da9664ce14fe4d55006e4a135 Mon Sep 17 00:00:00 2001 From: heimoshuiyu Date: Sun, 5 Jan 2025 16:39:44 +0800 Subject: [PATCH] drop states in block --- src/main.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5c243d8..5e26333 100644 --- a/src/main.rs +++ b/src/main.rs @@ -86,14 +86,15 @@ impl Downloader { .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))?; // notify all waiters - let mut states = self.states.lock().await; - let state = states.remove(target_url).unwrap(); - state.result.lock().await.replace(Ok(DownloadData { - body: body.clone(), - headers: headers.clone(), - })); - state.notify.notify_waiters(); - drop(states); + { + let mut states = self.states.lock().await; + let state = states.remove(target_url).unwrap(); + state.result.lock().await.replace(Ok(DownloadData { + body: body.clone(), + headers: headers.clone(), + })); + state.notify.notify_waiters(); + } Ok(DownloadData { body, headers }) }