Skip to content

Instantly share code, notes, and snippets.

@wayneseymour
Created February 4, 2021 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wayneseymour/73d7674e464006da3af13dcb98df79cc to your computer and use it in GitHub Desktop.
Save wayneseymour/73d7674e464006da3af13dcb98df79cc to your computer and use it in GitHub Desktop.
Asynchronous for reach using recursion.
const id = x => x;
const asyncForEach = async (xs, i) => {
const res = await Promise.resolve(xs[i])
console.log(`\n### const res: \n\t${res}`);
i++
i === xs.length ? id() : asyncForEach(xs, i)
}
const run = async () => asyncForEach(['a', 'b', 'c'], 0);
run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment