I have a method that returns an promise of an object (by id) from a database asynchronously.
function getObj(id){}....returns promise of object
It may or may not have a reference to another object by storing its id.
object.nextObjId
I need to traverse the reference chain until I find the terminal object using this method. Obviously I must wait for the promise to resolve before I can check for the next reference.
In synchronous code it would look like this:
function getTerminalObj(id)
{
var obj = getObj(id);
while(obj.nextRef)
{
obj = getObj(obj.nextObjId);
}
return obj;
}
How do I do this when getObj(id) instead returns a promise of an object?