Mercurial > hg > webaudioevaluationtool
changeset 3118:f78a66fbc018
Better asynchronous catcher. If a long queue of file uploads builds up, will resolve to the last in the queue
author | Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk> |
---|---|
date | Wed, 18 Jul 2018 14:47:14 +0100 |
parents | 76cffc7ecdee |
children | aa4503f8c630 |
files | js/core.js |
diffstat | 1 files changed, 15 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- 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); }