summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/core
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2018-09-03 14:47:34 +0200
committerAaron Bohy <aab@odoo.com>2018-09-05 08:47:21 +0200
commitf29f131f859c18020447bc0a08d073843beeb8ba (patch)
tree050ed884570aa3d99a6dcd11bfcd8a5997f082c3 /addons/web/static/src/js/core
parent71254e956d2025bdf13f8906a1a80f24447de373 (diff)
[IMP] web: concurrency: add getUnlockedDef to mutex
This rev. adds a new function to the mutex concurrency helper: 'getUnlockedef'. This function returns a deferred resolved as soon as the mutex has no more task to execute (or directly if it is currently idle). Such a function was needed for an upcoming fix. Related to task 1878254.
Diffstat (limited to 'addons/web/static/src/js/core')
-rw-r--r--addons/web/static/src/js/core/concurrency.js18
1 files changed, 16 insertions, 2 deletions
diff --git a/addons/web/static/src/js/core/concurrency.js b/addons/web/static/src/js/core/concurrency.js
index 20247d1c483..6eeebe7ff58 100644
--- a/addons/web/static/src/js/core/concurrency.js
+++ b/addons/web/static/src/js/core/concurrency.js
@@ -201,6 +201,7 @@ return {
Mutex: Class.extend({
init: function () {
this.def = $.Deferred().resolve();
+ this.unlockedDef = undefined;
},
/**
* Add a computation to the queue, it will be executed as soon as the
@@ -210,14 +211,27 @@ return {
* @returns {Deferred}
*/
exec: function (action) {
+ var self = this;
var current = this.def;
var next = this.def = $.Deferred();
+ this.unlockedDef = this.unlockedDef || $.Deferred();
return current.then(function() {
- return $.when(action()).always(function() {
+ return $.when(action()).always(function () {
next.resolve();
+ if (self.def.state() === 'resolved' && self.unlockedDef) {
+ self.unlockedDef.resolve();
+ self.unlockedDef = undefined;
+ }
});
});
- }
+ },
+ /**
+ * @returns {Promise} resolved as soon as the Mutex is unlocked
+ * (directly if it is currently idle)
+ */
+ getUnlockedDef: function () {
+ return $.when(this.unlockedDef);
+ },
}),
/**
* A MutexedDropPrevious is a primitive for serializing computations while