# HG changeset patch # User Nicholas Jillings # Date 1531921634 -3600 # Node ID f78a66fbc0181f093b8909a874807e9f0032ff2b # Parent 76cffc7ecdee2a576a00c74b3bdd05b9d36bc1be Better asynchronous catcher. If a long queue of file uploads builds up, will resolve to the last in the queue diff -r 76cffc7ecdee -r f78a66fbc018 js/core.js --- a/js/core.js Wed Jul 18 14:17:32 2018 +0100 +++ b/js/core.js Wed Jul 18 14:47:14 2018 +0100 @@ -3836,13 +3836,17 @@ if (window.returnURL !== undefined) { returnURL = String(window.returnURL); } + + var chainCount = 0; + var chainPosition = chainCount; function postUpdate() { - // Return a new promise. - var hold = document.createElement("div"); - var clone = parent.root.cloneNode(true); - hold.appendChild(clone); return new Promise(function (resolve, reject) { + // Return a new promise. + chainPosition+=1; + var hold = document.createElement("div"); + var clone = parent.root.cloneNode(true); + hold.appendChild(clone); // Do the usual XHR stuff console.log("Requested save..."); var req = new XMLHttpRequest(); @@ -3876,7 +3880,12 @@ }; // Make the request - req.send([hold.innerHTML]); + if (chainCount > chainPosition) { + // We have items downstream that will upload for us + resolve(true); + } else { + req.send([hold.innerHTML]); + } }); } @@ -3960,6 +3969,7 @@ if (requestChains === undefined) { throw ("Initiate key exchange first"); } + chainCount += 1; this.parent.root.setAttribute("state", "update"); requestChains = requestChains.then(postUpdate); }