Last active
November 17, 2022 23:07
-
-
Save ccnokes/9eec2d26b7e6f3bfcb29217779ed2c42 to your computer and use it in GitHub Desktop.
Takes a list of async functions and executes them one at a time. You could just use a `for of` loop for this too π
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* takes a list of async functions and executes them one at a time | |
*/ | |
async function serial( | |
fnList: Array<() => Promise<void>>, | |
nextIndex?: number = 0, | |
) { | |
let current = fnList[nextIndex]; | |
if (!current) return; | |
try { | |
await current(); | |
} catch (err) { | |
console.error(err); | |
} | |
await serial(fnList, nextIndex + 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment