Skip to content

Instantly share code, notes, and snippets.

@linktohack
Created March 20, 2019 04:44
Show Gist options
  • Save linktohack/d4c936cd234ff2974df6567c30b12bd4 to your computer and use it in GitHub Desktop.
Save linktohack/d4c936cd234ff2974df6567c30b12bd4 to your computer and use it in GitHub Desktop.
series
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