Skip to content

Commit

Permalink
make next_client_id a lambda
Browse files Browse the repository at this point in the history
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
#66 (comment)
  • Loading branch information
EliteTK authored and pr2502 committed Jun 4, 2024
1 parent 2c9cc6f commit 07f4467
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ 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(
Expand Down

0 comments on commit 07f4467

Please sign in to comment.