Skip to content

Instantly share code, notes, and snippets.

@naartjie
Forked from RReverser/gist:0a0263ec5abc5db03e05
Last active September 3, 2015 08:35
Show Gist options
  • Save naartjie/132976f1361c9767ce66 to your computer and use it in GitHub Desktop.
Save naartjie/132976f1361c9767ce66 to your computer and use it in GitHub Desktop.
async await
async function walk (dir, visitor) {
const filenames = await fs.readdirAsync(dir)
await* filenames
.map(filename => path.join(dir, filename))
.map(async filename => {
const stat = await fs.statAsync(filename)
if (stat.isDirectory()) {
await walk(filename, visitor)
} else {
visitor(filename, stat)
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment