1
0
Fork 0
mirror of synced 2024-09-10 14:35:47 +12:00

Update sequential helper to properly queue promises

This commit is contained in:
Andrew Kingston 2022-07-14 16:17:25 +01:00
parent e3c2d57b0e
commit 0d2509a7f6

View file

@ -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
} }
} }