Browse Source

Update sequential helper to properly queue promises

master
Andrew Kingston 4 years ago
parent
commit
c24c5b2861
  1. 16
      packages/frontend-core/src/utils/utils.js

16
packages/frontend-core/src/utils/utils.js

@ -5,13 +5,17 @@
* @return {Promise} a sequential version of the function * @return {Promise} a sequential version of the function
*/ */
export const sequential = fn => { export const sequential = fn => {
let promise let queue = []
return async (...params) => { return async (...params) => {
if (promise) { queue.push(async () => {
await promise 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
} }
} }

Loading…
Cancel
Save