Is PhotonNetwork.LeaveLobby() async?

I believe it is. However in "DemoAsteroids" the check is made as if it were not asynchronous:
if (!PhotonNetwork.InLobby)
{
    PhotonNetwork.JoinLobby();
}
Is it correct?

If PhotonNetwork.LeaveLobby() is async the client could be in the process of leaving the lobby but the PhotonNetwork.InLobby could be still true. In this case, we are skipping joining the lobby but then in a moment, the "Leave" operation could be completed and the client will stay out of the lobby eventually. Of course, this is not a very likely situation, but it can still happen.

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    edited October 2019
    Hi @develax,

    PhotonNetwork.InLobby (like PhotonNetwork.InRoom) is a helper or shortcut property that tells you if the state of the networking client (which is only a local cached state) matches a certain value.
    From the moment you call PhotonNetwork.LeaveLobby which is async yes, but should not fail (unless called on the wrong server or outside a lobby), PhotonNetwork.InLobby becomes false if it's not already the case.

    Besides the code snippet is from a button's on click action handler.
  • Hi @JohnTube ,
    JohnTube said:


    From the moment you call PhotonNetwork.LeaveLobby which is async yes, but should not fail (unless called on the wrong server or outside a lobby), PhotonNetwork.InLobby becomes false if it's not already the case.

    It doesn't seem to work this way.
    private void LeaveLobby()
    {
        if (PhotonNetwork.InLobby)
        {
            bool isLeft = PhotonNetwork.LeaveLobby(); // true
            bool inLobby = PhotonNetwork.InLobby; // true
        }
    }

  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @develax,

    I may be wrong on this yes.
    I did not look at the code.

    But what matters is that there should not be an issue here.
    You could add an extra check or queue joining until leaving is done.

    If you're worried about this you could add flags or make use of the detailed ClientState values to prevent actions while there are ones in process OR queue them to be processed once the client is in an idle state.