Promise.all works like this: you give it
an array of promises, and it returns a
single promise that is resolved when all the initial promises are done.
Meaning, in a case like this:
Promise.all([p1, p2, p3, ..., pn])
.then(handlerFuinction)
.catch(errorHandlerFunction);
In the example above, you give a handler (callback), but it won't get called until ALL of the p1, p2, p3.. are resolved.
If any of the promises fails or throws, your entire chain will get canceled. Now be careful here, some of the promises may have been resolved already (e.g. updated stuff in db), while others are still in progress, so you might have to do some cleanup call in the .catch handler.
In your case, you first have a promise to be something of this:
So if a call to this endpoint was authenticated (I assume that's wath auth.optional does), we get a User.findById(), otherwise we just get null (without going to db).
So in any case, your first promise will either return a user object or it will return null.
Your second promise is that execPopulate() promise.
Now, when both of these are done (both getting the user and populating that article), your last handler gets called. But if any of those fails (e.g. the database is down or the network breaks or whatever)
Well, I can't tell easily without looking in the code, but it looks like you can take out the second call to populate. That'd be the second promise in your Promise.all array. You could also skip the router.param up there completely, but you may be using that somewhere later on the router, so make sure it all works without it if you go that route (no pun intended :)).