diff options
Diffstat (limited to 'lib/js/urweb.js')
-rw-r--r-- | lib/js/urweb.js | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/lib/js/urweb.js b/lib/js/urweb.js index c37ff07d..98b615c0 100644 --- a/lib/js/urweb.js +++ b/lib/js/urweb.js @@ -627,7 +627,20 @@ function getXHR(uri) var sig = null; +var unloading = false, inFlight = null; + +function unload() { + unloading = true; + + for (; inFlight; inFlight = inFlight.next) { + inFlight.data.abort(); + } +} + function requestUri(xhr, uri, needsSig) { + if (unloading) + return; + xhr.open("POST", uri, true); if (client_id != null) { @@ -642,9 +655,15 @@ function requestUri(xhr, uri, needsSig) { xhr.setRequestHeader("UrWeb-Sig", sig); } + inFlight = cons(xhr, inFlight); xhr.send(null); } +function xhrFinished(xhr) { + xhr.abort(); + inFlight = remove(xhr, inFlight); +} + function rc(prefix, uri, parse, k, needsSig) { uri = cat(prefix, uri); uri = flattenLocal(uri); @@ -668,6 +687,8 @@ function rc(prefix, uri, parse, k, needsSig) { } else { conn(); } + + xhrFinished(xhr); } }; @@ -772,7 +793,7 @@ function listener() { } } - xhr.abort(); + xhrFinished(xhr); connect(); } @@ -786,7 +807,7 @@ function listener() { }; onTimeout = function() { - xhr.abort(); + xhrFinished(xhr); connect(); }; |