Fix ordering of messages
This commit is contained in:
parent
ae52b25baa
commit
c6a8c417ef
1 changed files with 8 additions and 7 deletions
|
|
@ -40,7 +40,7 @@ async fn main() -> Result<()> {
|
|||
// Infinite loop to always listen to new connections on this IP/PORT
|
||||
loop {
|
||||
let (stream, address) = listener.accept().await?;
|
||||
let (tx, mut rx) = (tx.clone(), tx.subscribe());
|
||||
let (tx, rx) = (tx.clone(), tx.subscribe());
|
||||
let db = db.clone();
|
||||
|
||||
tokio::spawn(async move {
|
||||
|
|
@ -63,12 +63,6 @@ async fn main() -> Result<()> {
|
|||
let message = compose_message(username.clone(), db.clone());
|
||||
info!("Adding username: {username} to db");
|
||||
let _ = framed.send(message).await;
|
||||
info!("Send message to client");
|
||||
let b = BroadcastMessage(
|
||||
username.clone(),
|
||||
format!("* {} has entered the room", username),
|
||||
);
|
||||
let _ = tx.send(b);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
|
@ -83,6 +77,13 @@ async fn main() -> Result<()> {
|
|||
}
|
||||
}
|
||||
|
||||
let b = BroadcastMessage(
|
||||
name.clone(),
|
||||
format!("* {} has entered the room", name),
|
||||
);
|
||||
let _ = tx.send(b);
|
||||
let mut rx = rx.resubscribe();
|
||||
|
||||
loop {
|
||||
tokio::select! {
|
||||
n = framed.next() => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue