I'm writing some code that currently looks like this because I have dependencies in my code. I was wondering if there was a cleaner way to do this with Promise.all()? Here is my pseudo code:
return someService.getUsername()
.then(function(username) {
user = username;
})
.then(function() {
return someService.getUserProps(user);
})
.then(function(userProps) {
userProperties = userProps;
return someService.getUserFriends(user);
})
.then(function(userFriends) {
friends = userFriends;
})
.catch(error)
.finally(function(){
// do stuff with results
});
The important thing is that I need user before I can make the second two calls for getUserProps() and getUserFriends(). I thought I could use Promise.all() for this like so:
var user = someService.getUsername()
.then(function(username) {
user = username;
})
var getUserProps = someService.getUserProps(user);
var getUserProps = someService.getUserFriends(user);
return Promise.all(user, getUserProps, getUserFriends, function(user, props, friends) {
// do stuff with results
})
But I cannot get this to work. Is this the correct case to use .all?