fix for race between polling and server response after update
This commit is contained in:
parent
f4318b2464
commit
9795c83583
|
|
@ -463,6 +463,8 @@ $(function (){
|
|||
head: 0, /* next item to be sent */
|
||||
tail: 0, /* ID to assign to the next update added to the queue */
|
||||
sending: false,
|
||||
idle: Promise.resolve(true), /* resolves to true if updates succeeded */
|
||||
signal_idle: function() {},
|
||||
|
||||
add(gameId, data, modified) {
|
||||
const wasEmpty = this.isEmpty();
|
||||
|
|
@ -474,6 +476,9 @@ $(function (){
|
|||
if (!this.sending) {
|
||||
openNoticeBox('Saving...');
|
||||
this.sending = true;
|
||||
this.idle = new Promise((resolve) => {
|
||||
this.signal_idle = resolve;
|
||||
});
|
||||
this.sendNext();
|
||||
}
|
||||
},
|
||||
|
|
@ -543,6 +548,7 @@ $(function (){
|
|||
|
||||
if (queue.isEmpty()) {
|
||||
queue.sending = false;
|
||||
queue.signal_idle(true);
|
||||
/* close the Saving... notice*/
|
||||
noticeBox.close({ ignoreDelay: true });
|
||||
} else {
|
||||
|
|
@ -559,6 +565,7 @@ $(function (){
|
|||
}
|
||||
|
||||
queue.sending = false;
|
||||
queue.signal_idle(false);
|
||||
|
||||
/* force a reset back to the latest server data */
|
||||
if (update.gameId === $('#cb_board').data('gameId')) {
|
||||
|
|
@ -643,6 +650,7 @@ $(function (){
|
|||
$('#cb_dark_name').val('');
|
||||
|
||||
cancelGameCallback = IO.onGameUpdate(newId, function(data, gameId) {
|
||||
updateQueue.idle.then(() => {
|
||||
if (data.modified > $('#cb_board').data('modified')) {
|
||||
try {
|
||||
const newGame = new PS.Game(JSON.stringify(data.board));
|
||||
|
|
@ -666,6 +674,7 @@ $(function (){
|
|||
$('#cb_board').data('modified', data.modified);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const notifyList = $('#cb_notify').data('gameList');
|
||||
const doNotify = notifyList.includes('*') || notifyList.includes(newId);
|
||||
|
|
|
|||
Loading…
Reference in New Issue