Skip to content

Commit

Permalink
Address race conditions if you finish an attempt before the first scr…
Browse files Browse the repository at this point in the history
…amble is ready (#57).
  • Loading branch information
lgarron committed Jul 15, 2016
1 parent c703b58 commit c281de4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cubing.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ Cubing.Scramblers.prototype = {
{
var callback = this._commandIdToCallback[e.data.commandId];
delete this._commandIdToCallback[e.data.commandId];
// TODO: Handle race conditions if the first attempt is done before the
// first scramble returns (possibly don't allow starting the timer without
// a valid scramble?).
callback(e.data.scramble)
}
}
3 changes: 2 additions & 1 deletion timerApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ TimerApp.prototype = {
var dateString = today.getFullYear() + "-" + (today.getMonth() + 1) + "-" + today.getDate();

var serializationFormat = "v0.1";
var result = "[" + serializationFormat + "][" + this._currentEvent + "][" + new Date() + "] " + (time / 1000) + " (" + this._currentScramble.scrambleString + ")";
var scrambleString = this._currentScramble ? this._currentScramble.scrambleString : "/* no scramble */";
var result = "[" + serializationFormat + "][" + this._currentEvent + "][" + new Date() + "] " + (time / 1000) + " (" + scrambleString + ")";

var store = (dateString in localStorage) ? localStorage[dateString] + "\n" : "";
localStorage[dateString] = store + result;
Expand Down

0 comments on commit c281de4

Please sign in to comment.