[IMP] web: abord the poll when destroy to avoid useless call

If the service bus are called and destroyed the rpc can be returned after, to
avoid a useless call to the database and unexpected behavior, we abort the
connection.
This commit is contained in:
Christophe Matthieu
2018-08-09 02:31:59 +02:00
parent 23c0c79128
commit 693c771111
3 changed files with 12 additions and 4 deletions
+5 -1
View File
@@ -53,6 +53,7 @@ bus.Bus = Widget.extend({
},
destroy: function () {
var self = this;
this.stop_polling();
$(window).off("focus." + this.bus_id);
$(window).off("blur." + this.bus_id);
$(window).off("unload." + this.bus_id);
@@ -70,6 +71,9 @@ bus.Bus = Widget.extend({
this.activated = false;
this.stop = true;
this.channels = [];
if (this._pollRpc) {
this._pollRpc.abort();
}
},
poll: function () {
var self = this;
@@ -89,7 +93,7 @@ bus.Bus = Widget.extend({
this._pollRpc.then(function (result) {
self._pollRpc = false;
self.on_notification(result);
if (!self.stop) {
if (!self.stop && self.activated) {
self.poll();
}
}, function (error, event) {
@@ -127,8 +127,10 @@ var ServicesMixin = {
*/
_rpc: function (params, options) {
var query = rpc.buildQuery(params);
var def = this.call('ajax', 'rpc', query.route, query.params, options);
return def ? def.promise() : $.Deferred().promise();
var def = this.call('ajax', 'rpc', query.route, query.params, options) || $.Deferred();
var promise = def.promise();
promise.abort = def.abort ? def.abort.bind(def) : function abort () {def.reject();};
return promise;
},
loadFieldView: function (dataset, view_id, view_type, options) {
return this.loadViews(dataset.model, dataset.get_context().eval(), [[view_id, view_type]], options).then(function (result) {
+3 -1
View File
@@ -346,7 +346,9 @@ var Session = core.Class.extend(mixins.EventDispatcherMixin, {
return deferred.then(function () {
if (aborted) {
return $.Deferred().reject('communication', $.Event(), 'abort', 'abort');
var def = $.Deferred().reject('communication', $.Event(), 'abort', 'abort');
def.abort = function () {};
return def;
}
// TODO: remove
if (! _.isString(url)) {