I extended the Actix web socket chat example a little bit. The chat rooms are Actors so thy can run some independent logic like a game.
In one Actor I have a handler for the message "Join". Inside this handler I want to send a message to another actor and wait for the response. How is this possible?
I use the addr.send().into_actor(self).then(...).wait(ctx) pattern.
But this doesent return anything else then ().
fn handle(&mut self, msg: Join, ctx: &mut Self::Context) -> Self::Result {
let Join {
session_id,
room_name,
old_room_addr,
} = msg;
// remove address from room and add to the new one.
let session_addr = match self.sessions.get(&session_id) {
Some(res) => res,
None => panic!("Session id is not in the chat server. This should not happend."),
};
old_room_addr
.send(RemoveSession(session_id))
.into_actor(self)
.then(|res, _act, _ctx|{
match res {
Ok(res) => {
if !res {
panic!("The session_id is not inside the room.");
}
},
Err(err) => panic!("Mailbox error while trying to remove the session from the room. {}", err),
}
fut::ready(())
})
.wait(ctx);
What I want is something like:
let result = old_room_addr.send(...).into_actor(...).then(...).wait(...);