mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-23 11:21:32 +00:00
* Use join_all instead of try_join_all. Fixes #2673 * Add note about closed connections.
This commit is contained in:
parent
c416e4ce14
commit
a8232fe3d6
1 changed files with 7 additions and 5 deletions
|
@ -5,7 +5,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
use actix_ws::Session;
|
use actix_ws::Session;
|
||||||
use anyhow::Context as acontext;
|
use anyhow::Context as acontext;
|
||||||
use futures::future::try_join_all;
|
use futures::future::join_all;
|
||||||
use lemmy_db_schema::newtypes::{CommunityId, LocalUserId, PostId};
|
use lemmy_db_schema::newtypes::{CommunityId, LocalUserId, PostId};
|
||||||
use lemmy_utils::{error::LemmyError, location_info, ConnectionId};
|
use lemmy_utils::{error::LemmyError, location_info, ConnectionId};
|
||||||
use rand::{rngs::StdRng, SeedableRng};
|
use rand::{rngs::StdRng, SeedableRng};
|
||||||
|
@ -231,13 +231,14 @@ impl ChatServer {
|
||||||
{
|
{
|
||||||
let msg = &serialize_websocket_message(&op, response)?;
|
let msg = &serialize_websocket_message(&op, response)?;
|
||||||
let sessions = self.inner()?.sessions.clone();
|
let sessions = self.inner()?.sessions.clone();
|
||||||
try_join_all(
|
// Note, this will ignore any errors, such as closed connections
|
||||||
|
join_all(
|
||||||
sessions
|
sessions
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter(|(id, _)| Some(id) != exclude_connection.as_ref())
|
.filter(|(id, _)| Some(id) != exclude_connection.as_ref())
|
||||||
.map(|(_, mut s): (_, Session)| async move { s.text(msg).await }),
|
.map(|(_, mut s): (_, Session)| async move { s.text(msg).await }),
|
||||||
)
|
)
|
||||||
.await?;
|
.await;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -368,14 +369,15 @@ impl ChatServer {
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let mut session = self.inner()?.sessions.clone();
|
let mut session = self.inner()?.sessions.clone();
|
||||||
if let Some(room) = room {
|
if let Some(room) = room {
|
||||||
try_join_all(
|
// Note, this will ignore any errors, such as closed connections
|
||||||
|
join_all(
|
||||||
room
|
room
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter(|c| Some(c) != exclude_connection.as_ref())
|
.filter(|c| Some(c) != exclude_connection.as_ref())
|
||||||
.filter_map(|c| session.remove(&c))
|
.filter_map(|c| session.remove(&c))
|
||||||
.map(|mut s: Session| async move { s.text(message).await }),
|
.map(|mut s: Session| async move { s.text(message).await }),
|
||||||
)
|
)
|
||||||
.await?;
|
.await;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue