http: rewrite retain function

This commit is contained in:
Joakim Frostegård 2022-03-23 21:24:53 +01:00
parent 9b85fa31d1
commit a348fcfd2d

View file

@ -73,7 +73,6 @@ pub async fn run_socket_worker(
let connection_slab = Rc::new(RefCell::new(Slab::new())); let connection_slab = Rc::new(RefCell::new(Slab::new()));
// Periodically remove closed connections
TimerActionRepeat::repeat(enclose!((config, connection_slab) move || { TimerActionRepeat::repeat(enclose!((config, connection_slab) move || {
clean_connections( clean_connections(
config.clone(), config.clone(),
@ -139,15 +138,15 @@ async fn clean_connections(
let now = Instant::now(); let now = Instant::now();
connection_slab.borrow_mut().retain(|_, reference| { connection_slab.borrow_mut().retain(|_, reference| {
let keep = reference.valid_until.0 > now; if reference.valid_until.0 > now {
true
if !keep { } else {
if let Some(ref handle) = reference.task_handle { if let Some(ref handle) = reference.task_handle {
handle.cancel(); handle.cancel();
} }
}
keep false
}
}); });
connection_slab.borrow_mut().shrink_to_fit(); connection_slab.borrow_mut().shrink_to_fit();