From: Raphaƫl Jakse Date: Sat, 4 Apr 2020 13:39:10 +0000 (+0200) Subject: Refactor: retry polling in a dedicated function X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=915c99da387ffc0e49af974dbc9ed3cc8bc4d54d;p=trivabble.git Refactor: retry polling in a dedicated function --- diff --git a/trivabble.js b/trivabble.js index 0659da6..2a3f3c3 100644 --- a/trivabble.js +++ b/trivabble.js @@ -669,6 +669,18 @@ } } + function retryPolling() { + pollingServer = false; + pollingReady = false; + + if (retriedImmediately) { + setTimeout(sendCmds.bind(null, []), POLLING_DELAY); + } else { + retriedImmediately = true; + sendCmds() + } + } + function send(data) { if (!pollingReady && ((data.cmds && data.cmds.length) && data.cmds[0].cmd !== "joinGame")) { sendCmds(); @@ -749,15 +761,7 @@ } } else if (xhr.readyState === 4) { if (thisRequestIsPolling) { - pollingServer = false; - pollingReady = false; - - if (retriedImmediately) { - setTimeout(sendCmds.bind(null, []), POLLING_DELAY); - } else { - retriedImmediately = true; - sendCmds() - } + retryPolling(); return; }