| 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));
|
| },
|
|
|
|
|