diff options
author | Adam Chlipala <adamc@hcoop.net> | 2009-11-24 09:24:25 -0500 |
---|---|---|
committer | Adam Chlipala <adamc@hcoop.net> | 2009-11-24 09:24:25 -0500 |
commit | 7463b805e4510b4f187851e91c53bb28db3ba044 (patch) | |
tree | c7e296a3f9f17fcb036db1231ba57d295924ddb0 /lib | |
parent | cf3fc72603a3ad499f2c3177beee709b3a5c53f8 (diff) |
Explicitly abort in-flight RPCs onunload
Diffstat (limited to 'lib')
-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(); }; |