Promises are confusing. The below is obviously bad, incomplete and not how I would actually go about doing it but should be enough to clear up my questions.
Given the below code, is the if statement blocked until the User.find promise is resolved? or is it a race condition to the console.log at the end?
var user = null;
if (....) {
User.find(123)
.on("success", function(u) {
user = u;
});
}
else {
// do something else to user
}
console.log(user.Name);
Likewise, if there is a promise being called within a promise is the outer promise(User.find) blocked until the inner one(Posts.findAll) is resolved? Again I know this is bad code, just trying to work out the flow and scope in my head.
var postlist = [];
User.find(123)
.on("success", function(user) {
Posts.findAll({where:{user_id:user.id}})
.on("success", function(posts) { postlist = posts});
});
console.log(postlist);
Again, I am not looking for the "correct or best" way of doing this, just trying to get a grasp on the flow and scope. Sorry to keep reiterating it, but I've grown tired of people not answering the questions asked in loo of offering their advice -- bad experiences on other sites, hopefully that wont happen here.