Each promise is for a hit on a database. I am doing a drill-down into a relational database. Each select that returns something might trigger more selects that are required.
So...I have an unknown number of promises to wait for. I am only really "finished" when all promises are done and there are no new ones added to the list.
My "db" object keeps an internal array of promises, and provides a "wait()" function to wait for all of them, but I never know when it's really done, so I end up doing this:
db.wait().then ->
db.wait().then ->
db.wait().then ->
db.wait().then ->
db.wait().then ->
console.log "finished waiting"
Which works, but only because I have a limited number of "levels". ( what if the number of "levels" was unlimited? )
Is there an existing pattern for accumulating promises where the handler might add more promises to the list?