From dabe5bfbae10de983bd1cbdba38949f17a62562e Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Mon, 10 Sep 2018 10:26:45 +0200 Subject: [FIX] web: ajax must return a promise with abort method Remove part in service_mixins who hide this error. Queries must be able to be canceled for better performance. Also in the case of longpolling, if the request is not canceled, wait for a server message or the maximum time (30 sec) to add or delete channels. --- addons/web/static/src/js/services/ajax_service.js | 25 +++++++++++++---------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'addons/web/static/src/js/services') diff --git a/addons/web/static/src/js/services/ajax_service.js b/addons/web/static/src/js/services/ajax_service.js index 3446f651a59..6c61fdbf9ed 100644 --- a/addons/web/static/src/js/services/ajax_service.js +++ b/addons/web/static/src/js/services/ajax_service.js @@ -8,17 +8,20 @@ var session = require('web.session'); var AjaxService = AbstractService.extend({ name: 'ajax', rpc: function (route, args, options, target) { - return $.Deferred(function (def) { - session.rpc(route, args, options).then(function () { - if (!target.isDestroyed()) { - def.resolve.apply(def, arguments); - } - }, function () { - if (!target.isDestroyed()) { - def.reject.apply(def, arguments); - } - }); - }).promise(); + var def = $.Deferred(); + var promise = def.promise(); + var xhrDef = session.rpc(route, args, options); + promise.abort = xhrDef.abort.bind(xhrDef); + xhrDef.then(function () { + if (!target.isDestroyed()) { + def.resolve.apply(def, arguments); + } + }).fail(function () { + if (!target.isDestroyed()) { + def.reject.apply(def, arguments); + } + }); + return promise; }, }); -- cgit v1.2.3