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
|
// Infinite loop to always listen to new connections on this IP/PORT
|
||||||
loop {
|
loop {
|
||||||
let (stream, address) = listener.accept().await?;
|
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();
|
let db = db.clone();
|
||||||
|
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
|
|
@ -63,12 +63,6 @@ async fn main() -> Result<()> {
|
||||||
let message = compose_message(username.clone(), db.clone());
|
let message = compose_message(username.clone(), db.clone());
|
||||||
info!("Adding username: {username} to db");
|
info!("Adding username: {username} to db");
|
||||||
let _ = framed.send(message).await;
|
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 {
|
} else {
|
||||||
return;
|
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 {
|
loop {
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
n = framed.next() => {
|
n = framed.next() => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue