diff --git a/addons/web/static/src/core/utils/concurrency.js b/addons/web/static/src/core/utils/concurrency.js index a81b163cb65..b7ac35d7bd0 100644 --- a/addons/web/static/src/core/utils/concurrency.js +++ b/addons/web/static/src/core/utils/concurrency.js @@ -1,5 +1,17 @@ /** @odoo-module **/ +/** + * Returns a promise resolved after 'wait' milliseconds + * + * @param {int} [wait=0] the delay in ms + * @return {Promise} + */ +export function delay(wait) { + return new Promise(function (resolve) { + setTimeout(resolve, wait); + }); +} + /** * KeepLast is a concurrency primitive that manages a list of tasks, and only * keeps the last task active. diff --git a/addons/web/static/src/legacy/js/core/concurrency.js b/addons/web/static/src/legacy/js/core/concurrency.js index 37319c50469..ef54edafc13 100644 --- a/addons/web/static/src/legacy/js/core/concurrency.js +++ b/addons/web/static/src/legacy/js/core/concurrency.js @@ -17,17 +17,6 @@ import Class from "@web/legacy/js/core/class"; const concurrency = { - /** - * Returns a promise resolved after 'wait' milliseconds - * - * @param {int} [wait=0] the delay in ms - * @return {Promise} - */ - delay: function (wait) { - return new Promise(function (resolve) { - setTimeout(resolve, wait); - }); - }, /** * The DropMisordered abstraction is useful for situations where you have * a sequence of operations that you want to do, but if one of them @@ -179,5 +168,4 @@ const concurrency = { } }; -export const delay = concurrency.delay export default concurrency; diff --git a/addons/web/static/src/legacy/js/core/dom.js b/addons/web/static/src/legacy/js/core/dom.js index 6b5cbab8f1e..4deee664908 100644 --- a/addons/web/static/src/legacy/js/core/dom.js +++ b/addons/web/static/src/legacy/js/core/dom.js @@ -10,7 +10,7 @@ */ import { uniqueId } from "@web/core/utils/functions"; -import concurrency from "@web/legacy/js/core/concurrency"; +import { delay } from "@web/core/utils/concurrency"; import core from "@web/legacy/js/services/core"; import { localization } from "@web/core/l10n/localization"; @@ -347,7 +347,7 @@ var dom = { // a 'real' debounce creation useless. Also, during the debouncing // part, the button is disabled without any visual effect. $button.addClass('pe-none'); - Promise.resolve(dom.DEBOUNCE && concurrency.delay(dom.DEBOUNCE)).then(function () { + Promise.resolve(dom.DEBOUNCE && delay(dom.DEBOUNCE)).then(function () { $button.removeClass('pe-none'); const restore = dom.addButtonLoadingEffect($button[0]); return Promise.resolve(result).then(restore).guardedCatch(restore); diff --git a/addons/web/static/src/webclient/barcode/barcode_scanner.js b/addons/web/static/src/webclient/barcode/barcode_scanner.js index efe6dba4d65..c2f5cbc6e2b 100644 --- a/addons/web/static/src/webclient/barcode/barcode_scanner.js +++ b/addons/web/static/src/webclient/barcode/barcode_scanner.js @@ -3,7 +3,7 @@ import { browser } from "@web/core/browser/browser"; import { Dialog } from "@web/core/dialog/dialog"; -import { delay } from "@web/legacy/js/core/concurrency"; +import { delay } from "@web/core/utils/concurrency"; import { loadJS } from "@web/core/assets"; import { isVideoElementReady, buildZXingBarcodeDetector } from "./ZXingBarcodeDetector"; import { CropOverlay } from "./crop_overlay"; diff --git a/addons/web/static/tests/legacy/helpers/test_utils_dom.js b/addons/web/static/tests/legacy/helpers/test_utils_dom.js index aeaa5bcdc03..bb56a21e549 100644 --- a/addons/web/static/tests/legacy/helpers/test_utils_dom.js +++ b/addons/web/static/tests/legacy/helpers/test_utils_dom.js @@ -1,6 +1,6 @@ /** @odoo-module **/ -import concurrency from "@web/legacy/js/core/concurrency"; +import { delay } from "@web/core/utils/concurrency"; /** * DOM Test Utils @@ -305,7 +305,7 @@ import concurrency from "@web/legacy/js/core/concurrency"; * @returns {Promise} */ async function returnAfterNextAnimationFrame() { - await concurrency.delay(0); + await delay(0); await new Promise(resolve => { window.requestAnimationFrame(resolve); }); diff --git a/addons/website/static/src/client_actions/configurator/configurator.js b/addons/website/static/src/client_actions/configurator/configurator.js index 51c03629b93..6b35c81a3e1 100644 --- a/addons/website/static/src/client_actions/configurator/configurator.js +++ b/addons/website/static/src/client_actions/configurator/configurator.js @@ -1,6 +1,6 @@ /** @odoo-module **/ -import concurrency from '@web/legacy/js/core/concurrency'; +import { delay } from "@web/core/utils/concurrency"; import utils from '@web/legacy/js/core/utils'; import weUtils from '@web_editor/js/common/utils'; import { _t } from "@web/core/l10n/translation"; @@ -332,7 +332,7 @@ class ApplyConfiguratorScreen extends Component { ); } catch (error) { // Wait a bit before retrying or allowing manual retry. - await concurrency.delay(5000); + await delay(5000); if (retryCount < 3) { return attemptConfiguratorApply(data, retryCount + 1); } diff --git a/addons/website/static/src/snippets/s_website_form/000.js b/addons/website/static/src/snippets/s_website_form/000.js index 8cd22149df4..22f48a15c97 100644 --- a/addons/website/static/src/snippets/s_website_form/000.js +++ b/addons/website/static/src/snippets/s_website_form/000.js @@ -6,7 +6,7 @@ import ajax from "@web/legacy/js/core/ajax"; import publicWidget from "@web/legacy/js/public/public_widget"; import dom from "@web/legacy/js/core/dom"; - import concurrency from "@web/legacy/js/core/concurrency"; + import { delay } from "@web/core/utils/concurrency"; import { debounce } from "@web/core/utils/timing"; import { _t } from "@web/core/l10n/translation"; import { renderToElement } from "@web/core/utils/render"; @@ -436,7 +436,7 @@ // Prevent double-clicking on the send button and // add a upload loading effect (delay before success // message) - await concurrency.delay(dom.DEBOUNCE); + await delay(dom.DEBOUNCE); self.el.classList.add('d-none'); self.el.parentElement.querySelector('.s_website_form_end_message').classList.remove('d-none'); @@ -446,7 +446,7 @@ // Prevent double-clicking on the send button and // add a upload loading effect (delay before success // message) - await concurrency.delay(dom.DEBOUNCE); + await delay(dom.DEBOUNCE); self.update_status('success'); break;