IDEMPIERE-175 Atmosphere server push. 1) Timeout shouldn't increase failure count. 2) Use oncomplete event to schedule the next long polling call and eliminate the duplicate code in onError and onSuccess. 3) Reduce the delay between complete and next long polling call from 250ms to 10ms. 4) stop should immediately set active to false.

This commit is contained in:
Heng Sin Low 2013-10-16 17:24:48 +08:00
parent f46d53670a
commit 5ee9dfc9b1
1 changed files with 12 additions and 9 deletions

View File

@ -15,7 +15,7 @@
jawwa.atmosphere.ServerPush = zk.$extends(zk.Object, { jawwa.atmosphere.ServerPush = zk.$extends(zk.Object, {
desktop: null, desktop: null,
active: false, active: false,
delay: 250, delay: 10,
failures: 0, failures: 0,
timeout: 0, timeout: 0,
ajaxOptions: { ajaxOptions: {
@ -34,17 +34,20 @@
this.ajaxOptions.timeout = this.timeout; this.ajaxOptions.timeout = this.timeout;
var me = this; var me = this;
this.ajaxOptions.error = function(jqxhr, textStatus, errorThrown) { this.ajaxOptions.error = function(jqxhr, textStatus, errorThrown) {
if (typeof console == "object") { if (textStatus != "timeout") {
console.error(textStatus); if (typeof console == "object") {
console.error(errorThrown); console.error(textStatus);
} console.error(errorThrown);
me.failures += 1; }
me._schedule(); me.failures += 1;
}
}; };
this.ajaxOptions.success = function(data) { this.ajaxOptions.success = function(data) {
zAu.cmd0.echo(this.desktop); zAu.cmd0.echo(this.desktop);
me.failures = 0; me.failures = 0;
me._schedule(); };
this.ajaxOptions.complete = function() {
me._schedule();
}; };
}, },
_schedule: function() { _schedule: function() {
@ -68,8 +71,8 @@
this._send(); this._send();
}, },
stop: function() { stop: function() {
this.desktop._serverpush = null;
this.active = false; this.active = false;
this.desktop._serverpush = null;
if (this._req) { if (this._req) {
this._req.abort(); this._req.abort();
this._req = null; this._req = null;