Skip to content

Instantly share code, notes, and snippets.

@colinf
Last active January 14, 2018 17:26
Show Gist options
  • Save colinf/f6fe805b750bf84a16b8c1dae4a1f11a to your computer and use it in GitHub Desktop.
Save colinf/f6fe805b750bf84a16b8c1dae4a1f11a to your computer and use it in GitHub Desktop.
Recursive function using ES8 async/await ( see https://medium.com/@softwarecf/a-faint-outline-2a2c641d6492 )
async function getChildren (id = 0) {
let childRows = await runJxa(readChildren, [id])
let result = await Promise.all(childRows.map(async child => {
let {hasChildren, ...resultChild} = child
if (!child.hasChildren) return resultChild
return {...resultChild, children: await getChildren(child.id)}
}))
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment