mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-09-25 22:29:45 +00:00
Turned a lot of function to async mode
This commit is contained in:
@@ -317,9 +317,16 @@ impl Actor for WsSession {
|
||||
fn stopping(&mut self, ctx: &mut Self::Context) -> Running {
|
||||
// Send an event (user_ws_closed)
|
||||
if let Some(conn) = find_connection(ctx.address()) {
|
||||
if let Err(e) = events_helper::propagate_event(&Event::UserWsClosed(&conn)) {
|
||||
eprintln!("Failed to propagate web socket closed event ! {:#?}", e);
|
||||
}
|
||||
let future = async move {
|
||||
if let Err(e) = events_helper::propagate_event(Event::UserWsClosed(conn)).await {
|
||||
eprintln!("Failed to propagate web socket closed event ! {:#?}", e);
|
||||
}
|
||||
|
||||
// TODO : remove
|
||||
eprintln!("Successfully propagated user ws stopping event!");
|
||||
};
|
||||
|
||||
future.into_actor(self).wait(ctx);
|
||||
}
|
||||
|
||||
remove_connection(ctx.address());
|
||||
@@ -495,10 +502,9 @@ pub fn send_to_client(conn: &UserWsConnection, msg: &UserWsMessage) -> Res {
|
||||
}
|
||||
|
||||
/// Send a message to specific users
|
||||
pub fn send_message_to_specific_connections<F, M, A>(filter: F, msg_generator: M, after_send: Option<A>) -> Res
|
||||
pub fn send_message_to_specific_connections<F, M>(filter: F, msg_generator: M) -> Res<Vec<UserWsConnection>>
|
||||
where F: Fn(&UserWsConnection) -> bool,
|
||||
M: Fn(&UserWsConnection) -> Res<UserWsMessage>,
|
||||
A: Fn(&UserWsConnection) -> Res
|
||||
M: Fn(&UserWsConnection) -> Res<UserWsMessage>
|
||||
{
|
||||
let connections = get_ws_connections_list()
|
||||
.lock()
|
||||
@@ -508,15 +514,11 @@ pub fn send_message_to_specific_connections<F, M, A>(filter: F, msg_generator: M
|
||||
.map(|f| f.clone())
|
||||
.collect::<Vec<UserWsConnection>>();
|
||||
|
||||
for con in connections {
|
||||
for con in &connections {
|
||||
send_message(con.session.clone(), &msg_generator(&con)?)?;
|
||||
|
||||
if let Some(cb) = &after_send {
|
||||
cb(&con)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
Ok(connections)
|
||||
}
|
||||
|
||||
/// Check out whether user is connected or not
|
||||
@@ -576,6 +578,11 @@ pub fn foreach_connection<F>(mut f: F) -> Res
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Get a copy of the entire list of connections
|
||||
pub fn get_all_connections() -> Res<Vec<UserWsConnection>> {
|
||||
Ok(get_ws_connections_list().lock().unwrap().clone())
|
||||
}
|
||||
|
||||
/// Events handler
|
||||
pub fn handle_event(e: &events_helper::Event) -> Res {
|
||||
match e {
|
||||
|
Reference in New Issue
Block a user