I have a need to recursively descend a linked list database tree
item 1-> item 2
-> item 3 -> item 4
-> item 5 -> item 6 -> item 7
-> item 8
my pseudo code is
var getItems = function(itemid) {
db.getitem(itemid, function(item) {
item.items.forEach(function(subitem) {
getItems(subitem.id)
})
})
getItems(1)
however, db.getItem
is an asynchronous function
I would like to return a JS object in the same structure as the diagram to the top-level caller
what is the best way of achieving this ? I don't know the structure up front (i.e. no idea on the number of items per item, or the depth of any branch in the tree) so I have no idea on the number of items I need to process
I have tried various methods of the async library, but none seem to deal with recursion