⚒️Thor, the Norseman⚒️ er en bruker på snabeltann.no. Du kan følge dem eller kommunisere med dem hvis du har en konto hvor som helst i fediverset. Hvis du ikke har en konto så kan du registrere deg her.
⚒️Thor, the Norseman⚒️

http.get({}, (res1) => {
...
items.forEach((item) => {
arr[item.id] = item
http.get({}, (subRes) => {
...
subItems.forEach((subItem => {
subArr[subItem.id] = subItem
})
})
})

What's a clean way of creating a single exit point from a construct like this?

@thor Won't it naturally exit after all the items and sub-items?

@machiavelli Yes, but I need to know when everything is finished...

I suppose I could count the items, put the sub-item HTTP calls into an array of promises, and fulfill each promise after the sub-items have been fetched and processed, and use Promise.all() to wait on the promise array...

@thor If it were Scala, I'd use Futures since they're cleaner syntactically, though I don't know if anyone has created something similar to abstract over time in JS.

@thor
Cleaner than promises. Was basing it on the context of the other post you had

@skypage Whatever I end up using, I probably can't use the data passing mechanism it implements, because I'm populating 3 hash maps with what more or less amounts to 3 relational views of the same data. I wish there was a more elegant way of doing it. At least I maintain data integrity, since all JS objects are assigned by reference.