diff options
| author | Sébastien Theys <seb@odoo.com> | 2020-10-27 13:16:28 +0000 |
|---|---|---|
| committer | Sébastien Theys <seb@odoo.com> | 2020-10-27 13:16:28 +0000 |
| commit | e78805fc3ae9b5dbbf72667e5bd62e5c5346cc53 (patch) | |
| tree | 90e6fa8d78a37ab527714cb266b4f830d33d3357 /addons/mail/static/src/utils | |
| parent | 4d2b8dd1bef40c592215728fab6c31f192176e93 (diff) | |
[FIX] mail, im_livechat: avoid artificially delaying messaging
Don't delay the insert of partners or channels until it actually takes too much
time.
Don't await `_initMentionPartnerSuggestions` as it is just nice to have.
task-2371485
closes odoo/odoo#60826
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
Diffstat (limited to 'addons/mail/static/src/utils')
| -rw-r--r-- | addons/mail/static/src/utils/utils.js | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/addons/mail/static/src/utils/utils.js b/addons/mail/static/src/utils/utils.js index 8112eeca980..f502fc8f326 100644 --- a/addons/mail/static/src/utils/utils.js +++ b/addons/mail/static/src/utils/utils.js @@ -15,6 +15,25 @@ const classPatchMap = new WeakMap(); const eventHandledWeakMap = new WeakMap(); /** + * Executes the provided functions in order, but with a potential delay between + * them if they take too much time. This is done in order to avoid blocking the + * main thread for too long. + * + * @param {function[]} functions + * @param {integer} [maxTimeFrame=100] time (in ms) until a delay is introduced + */ +async function executeGracefully(functions, maxTimeFrame = 100) { + let startDate = new Date(); + for (const func of functions) { + if (new Date() - startDate > maxTimeFrame) { + await new Promise(resolve => setTimeout(resolve)); + startDate = new Date(); + } + await func(); + } +} + +/** * Returns whether the given event has been handled with the given markName. * * @param {Event} ev @@ -147,6 +166,7 @@ function unpatchInstanceMethods(Class, patchName) { //------------------------------------------------------------------------------ return { + executeGracefully, isEventHandled, markEventHandled, nextTick, |
