From 38d98cf9192d6b12b1680e31e6ed4d337ec8f567 Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Tue, 4 Jun 2024 18:45:34 +0100 Subject: [PATCH] make next_client_id a lambda This is neater at the call site and makes it clear that this is only ever supposed to be an incremental ID and nothing else. As suggested by max (pr2502) in https://github.com/pr2502/ra-multiplex/pull/66#discussion_r1626394771 --- src/server.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/server.rs b/src/server.rs index 67a6b77..338cc81 100644 --- a/src/server.rs +++ b/src/server.rs @@ -12,13 +12,14 @@ use crate::socketwrapper::Listener; pub async fn run(config: &Config) -> Result<()> { let instance_map = InstanceMap::new(config).await; let next_client_id = AtomicUsize::new(0); + let next_client_id = || next_client_id.fetch_add(1, Ordering::Relaxed); let listener = Listener::bind(&config.listen).await .context("listen")?; loop { match listener.accept().await { Ok((socket, _addr)) => { - let client_id = next_client_id.fetch_add(1, Ordering::Relaxed); + let client_id = next_client_id(); let instance_map = instance_map.clone(); task::spawn(