Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2760)

Unified Diff: appengine/swarming/elements/res/imp/common/common-behavior.html

Issue 2337363004: Add task-page (Closed) Base URL: git@github.com:luci/luci-py@task-data
Patch Set: Alignment take 2 Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: appengine/swarming/elements/res/imp/common/common-behavior.html
diff --git a/appengine/swarming/elements/res/imp/common/common-behavior.html b/appengine/swarming/elements/res/imp/common/common-behavior.html
index a31ab81e35cbb7abc8702435d5bb3d1cb4eb6d25..3481d34e92b0515fdd030c6b33bfb4193be886f1 100644
--- a/appengine/swarming/elements/res/imp/common/common-behavior.html
+++ b/appengine/swarming/elements/res/imp/common/common-behavior.html
@@ -38,28 +38,39 @@
// error, bindTo will be set to false. It is not set to undefined
// because computed values in Polymer don't fire if a property is
// undefined. Clients should check that bindTo is not falsey.
+ // To avoid multiple requests clobering one another, an object _jsonAsync
+ // is created on "this" to debounce requests - the most recent request
+ // will win out.
_getJsonAsync: function(bindTo, url, busy, headers, params) {
- if (!bindTo || !url) {
- console.log("Need at least a polymer element to bind to and a url");
+ if (!bindTo || !url || !busy) {
+ console.log("Need at least a polymer element to bind to, a busy element, and a url");
return;
}
- if (busy) {
- this.set(busy, true);
- }
+ this.set(busy, true);
+ var now = new Date();
+ this._jsonAsync = this._jsonAsync || {};
+ this._jsonAsync[bindTo] = now;
if (params) {
url = url + "?" + sk.query.fromParamSet(params);
}
sk.request("GET", url, "", headers).then(JSON.parse).then(function(json){
+ if (this._jsonAsync[bindTo] !== now) {
+ console.log("ignoring result because a second request happened.");
+ this.set(busy, false);
+ return;
+ }
this.set(bindTo, json);
- if (busy) {
- this.set(busy, false);
- }
+ this.set(busy, false);
}.bind(this)).catch(function(reason){
console.log("Reason for failure of request to " + url, reason);
+
+ if (this._jsonAsync[bindTo] !== now) {
+ console.log("ignoring failure because a second request happened.");
+ this.set(busy, false);
+ return;
+ }
this.set(bindTo, false);
- if (busy) {
- this.set(busy, false);
- }
+ this.set(busy, false);
}.bind(this));
},

Powered by Google App Engine
This is Rietveld 408576698