amaatouq/netwise

Sync get() and set() api

Closed this issue · 9 comments

At the moment, the get() and set() functions are asynchronous on the server which makes doing something tricky. For example, in the "guess the correlation game" after the interactive stage, we want to compute the scores first, and then color the scores based on their ranking. This means in this code:

  onStageEnd(game, round, stage, players) {
    if (stage.name === "response") {
      computeScore(players, round);
    } else if (stage.name === "interactive") {
      computeScore(players, round);
      colorScores(players);
    } else {
      return null;
    }
  },

We need the computeScore(.) should happen before colorScores(.) but it is not the case as computeScore(.) is non-blocking.

I am sure it is not blocking and ordered. If you go to the "Guess the correlation" example, you'll see that the scores seen by the colorScores() are the scores computed at the response stage and not the interactive stage .. to replicate this error, play a round of guess the correlation, and if the ranking of the players in term of performance changes from the response stage to the interactive stage, you will get the wrong colors in the round outcome.

@amaatouq Can you check if this is working now? Thanks!

@npaton it seems that it is working in the sense that the first function runs before the second one. But I still have a weird behavior.

in the function onStageEnd(.) if I do player.round.set("score", score); and then afterwards player.round.get("score") I get undefined value. Although the score is defined by a numerical value. It is until the next stage begins, then it becomes populated with the right value that we set. This is what's causing the weird behavior with the coloring (i.e., the coloring function doesn't have access to the player.round.get("score") that was set by the player.round.set("score", score); in computing the score function. As both happen between the 'interactive' and 'outcome' stages.

Oh, right, my bad, I know why. Will fix.

It could be that the functions were always blocking .. This was the problem from the start (as my test case was computing the score and then coloring based on that computed scores)

Ok, it is working as expected now!