Last active
January 14, 2018 17:26
-
-
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 )
This file contains hidden or 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
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