amaatouq / netwise

open source project to tackle the problem of long development cycles required to produce software to conduct multi-participant and real-time human experiments online.
1 stars 0 forks source link

Sync get() and set() api #10

Closed amaatouq closed 6 years ago

amaatouq commented 6 years ago

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.

npaton commented 6 years ago

Are they? Is this something you have tested? Ok the server, meteor uses Fibers to block during asynchronous operations, so all of that should be blocking and ordered.

On 11 Mar 2018, at 03:21, Abdullah notifications@github.com wrote:

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.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

amaatouq commented 6 years ago

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.

npaton commented 6 years ago

Ok. There is a bug. These functions should be blocking.

On Sun, Mar 11, 2018 at 9:47 PM, Abdullah notifications@github.com wrote:

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.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/amaatouq/netwise/issues/10#issuecomment-372116890, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAlzqe44k817uXtiGWIqSTe8pVzyOseks5tdSrzgaJpZM4SlZx5 .

npaton commented 6 years ago

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

amaatouq commented 6 years ago

@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.

npaton commented 6 years ago

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

amaatouq commented 6 years ago

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)

npaton commented 6 years ago

Yes, I got confused a bit there. They are blocking, but I was not updating the in-memory copy of the object. I think it should be good now.

On Fri, Mar 23, 2018 at 10:24 PM, Abdullah notifications@github.com wrote:

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)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/amaatouq/netwise/issues/10#issuecomment-375681622, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAlzkZ75PB5yUiekIRKcrkwA_aSn-Xuks5thQWvgaJpZM4SlZx5 .

amaatouq commented 6 years ago

Ok, it is working as expected now!