Created
February 4, 2021 21:55
-
-
Save wayneseymour/73d7674e464006da3af13dcb98df79cc to your computer and use it in GitHub Desktop.
Asynchronous for reach using recursion.
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
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