Created
March 20, 2019 04:44
-
-
Save linktohack/d4c936cd234ff2974df6567c30b12bd4 to your computer and use it in GitHub Desktop.
series
This file contains hidden or 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
async function series<T>(promises: (() => Promise<T>)[],): Promise<T[]> { | |
const results: T[] = []; | |
async function seriesInner(promises: (() => Promise<T>)[]): Promise<T[]> { | |
if (promises.length > 0) { | |
const p = promises.shift(); | |
const result = await p(); | |
results.push(result); | |
return seriesInner(promises); | |
} else { | |
return results; | |
} | |
} | |
seriesInner(promises); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment