Update sequential helper to properly queue promises
This commit is contained in:
parent
3e4cf89765
commit
c24c5b2861
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue