diff --git a/src/utils/async-queue.js b/src/utils/async-queue.js index 3e1d24995e..f8a740417f 100644 --- a/src/utils/async-queue.js +++ b/src/utils/async-queue.js @@ -6,8 +6,14 @@ export function isInQueue (key) { export function addToQueue (key, asyncAction) { const action = actions[key] || Promise.resolve(); + const nextAction = action.then(() => asyncAction()); - actions[key] = action.then(() => asyncAction()); + actions[key] = nextAction; - return actions[key]; + nextAction.finally(() => { + if (actions[key] === nextAction) + delete actions[key]; + }); + + return nextAction; }