From a348fcfd2db55c86a739170379a9e50108d6a690 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Frosteg=C3=A5rd?= Date: Wed, 23 Mar 2022 21:24:53 +0100 Subject: [PATCH] http: rewrite retain function --- aquatic_http/src/workers/socket.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/aquatic_http/src/workers/socket.rs b/aquatic_http/src/workers/socket.rs index 8c8b512..56e91bd 100644 --- a/aquatic_http/src/workers/socket.rs +++ b/aquatic_http/src/workers/socket.rs @@ -73,7 +73,6 @@ pub async fn run_socket_worker( let connection_slab = Rc::new(RefCell::new(Slab::new())); - // Periodically remove closed connections TimerActionRepeat::repeat(enclose!((config, connection_slab) move || { clean_connections( config.clone(), @@ -139,15 +138,15 @@ async fn clean_connections( let now = Instant::now(); connection_slab.borrow_mut().retain(|_, reference| { - let keep = reference.valid_until.0 > now; - - if !keep { + if reference.valid_until.0 > now { + true + } else { if let Some(ref handle) = reference.task_handle { handle.cancel(); } - } - keep + false + } }); connection_slab.borrow_mut().shrink_to_fit();