开发者

State Change After Update (by Another User) But Before Poll

suppose we have the following scenario:

  1. 2 users both signal ready to play, the rails app receives it and starts a game
  2. one of the 2 users issue a "forfeit" via ajax immediately (im assuming it's not possible to prevent that, amirite?)
  3. by the time the other user polls to figure out whether a game has started, the game has already ended and scores updated
  4. that user is confused

I'm not quite sure what to do here. Can anyone give me some ideas?


Alright, I figured out what I did wrong. (cant self answer yet because my rep is too low)

When a user polls to figure out whether his/her game has started, and to receive moves and etc, I check "game in progress" and "user = user polling" attributes to figure out what to respond. But that's wrong, because as soon as the ends, this logic fails to find the rel开发者_开发知识库evant game to retrieve data from and give back to the user.

What I'm think of right now is, add "end game has been polled" as an attribute to the game object (well, playing objects through relationships) so if a game ended but has not been polled, the user will receive it once then respond to confirm. Then the game will not be polled again.


The flag indicating the game has ended should allow for different values indicating why the game ended. When player 1 forfeits, the flag is updated to indicate forfeiture. Then when player 2 polls to get status, he is told of the forfeiture.


Alright, I figured out what I did wrong.

When a user polls to figure out whether his/her game has started, and to receive moves and etc, I check "game in progress" and "user = user polling" attributes to figure out what to respond. But that's wrong, because as soon as the ends, this logic fails to find the relevant game to retrieve data from and give back to the user.

What I'm think of right now is, add "end game has been polled" as an attribute to the game object (well, playing objects through relationships) so if a game ended but has not been polled, the user will receive it once then respond to confirm. Then the game will not be polled again.

However, there is now a new question, as in what if there are multiple state changes in-between polls.

Maybe polling for state is just wrong? Perhaps I need a buffer queue that records state changes in order for polling? I don't know yet.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜