From c24c5b2861c5023ce766fac8b2f93f1fe8196654 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 14 Jul 2022 16:17:25 +0100 Subject: [PATCH] Update sequential helper to properly queue promises --- packages/frontend-core/src/utils/utils.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/frontend-core/src/utils/utils.js b/packages/frontend-core/src/utils/utils.js index afa88a0624..fc24aa67f1 100644 --- a/packages/frontend-core/src/utils/utils.js +++ b/packages/frontend-core/src/utils/utils.js @@ -5,13 +5,17 @@ * @return {Promise} a sequential version of the function */ export const sequential = fn => { - let promise + let queue = [] return async (...params) => { - if (promise) { - await promise + queue.push(async () => { + await fn(...params) + queue.pop() + if (queue.length) { + await queue[0]() + } + }) + if (queue.length === 1) { + await queue[0]() } - promise = fn(...params) - await promise - promise = null } }